Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Border thickness in TableCellRenderer too thick...

Thread view: 
Dag Sunde - 24 May 2006 11:52 GMT
I have the class below, implementing TableCellRenderer
to use as a custom-renderer for my ColumnHeaders in a JTable.

It works great concerning foreground-color, background-color
and font type/style, but when it comes to the border it
fails me a little bit...:

I would have thought that the line:
  setBorder( new LineBorder(Color.decode("#536B7D"),1, false));
would give me a single pixel thick border that matched the thickness
of the cells in the table itself.

But it gives me a fatter (2px) wide border around each column header.
I try to achieve a 'flat' look on the column-headers...

Anyone have a tip to what I do wrong?

//--------------------------
package no.viz.regweb.rk;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import javax.swing.border.*;

public class ColoredHeadRenderer extends JLabel
   implements TableCellRenderer {

 private Dimension preferredSize;

 ColoredHeadRenderer () {
  this (new Dimension (80, 17));
 }

 ColoredHeadRenderer (Dimension preferredSize) {
  this.preferredSize = preferredSize;
  setOpaque (true);
  setBorder( new LineBorder(Color.decode("#536B7D"),1, false));
 }

 public Dimension getPreferredSize () {
  return preferredSize;
 }

 public Component getTableCellRendererComponent (JTable table,
                         Object value,
                         boolean isSelected,
                         boolean hasFocus,
                         int row,
                         int col) {

   if (value instanceof String) {
     String s = (String) value;
     setFont(new Font("Arial", Font.BOLD, 11));
     setForeground(Color.decode("#536B7D"));
     setBackground(Color.decode("#c8cfd5"));
     // Save the string in preparation to rendering.
     setText (s);
   }

   return this;
 }
}

Signature

Dag.

Remon van Vliet - 24 May 2006 13:07 GMT
>I have the class below, implementing TableCellRenderer
> to use as a custom-renderer for my ColumnHeaders in a JTable.
[quoted text clipped - 12 lines]
>
> Anyone have a tip to what I do wrong?
*SNIP*

Well i'm no Swing expert, but if you have two cells next to eachother with a
border of 1pixel, then logic would suggest that the line shows as a one of 2
pixels wide (since your 1 pixel border is against the 1 pixel border of the
neighbouring cell). But then  , like i said, i'm no Swing expert..

Remon
Dag Sunde - 24 May 2006 13:50 GMT
>>I have the class below, implementing TableCellRenderer
>> to use as a custom-renderer for my ColumnHeaders in a JTable.
[quoted text clipped - 18 lines]
> of 2 pixels wide (since your 1 pixel border is against the 1 pixel border
> of the neighbouring cell). But then  , like i said, i'm no Swing expert..

Looking closer, i think you're right...
I didn't think it was that because I have fat top and bottom edges too...
But that is actually the border around the scrollpane on top, and the
top-row of the cells at the bottom of the header...

Can anyone explain to me how I make a border with only the right and bottom
line visible?

TIA...

Signature

Dag.

Dag Sunde - 24 May 2006 13:55 GMT
<snipped/>
>> Well i'm no Swing expert, but if you have two cells next to eachother
>> with a border of 1pixel, then logic would suggest that the line shows as
[quoted text clipped - 10 lines]
> bottom
> line visible?

Belay that question... :-)

This did the trick:
 Border b = new MatteBorder(0,0,1,1,Color.decode("#536B7D"));

Thanks!

Signature

Dag.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.