Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Border thickness in TableCellRenderer too thick...

Reply
Thread Tools

Border thickness in TableCellRenderer too thick...

 
 
Dag Sunde
Guest
Posts: n/a
 
      05-24-2006
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;
}
}

--
Dag.


 
Reply With Quote
 
 
 
 
Remon van Vliet
Guest
Posts: n/a
 
      05-24-2006
"Dag Sunde" <(E-Mail Removed)> wrote in message
news:44743af5$(E-Mail Removed)...
>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?

*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


 
Reply With Quote
 
 
 
 
Dag Sunde
Guest
Posts: n/a
 
      05-24-2006
"Remon van Vliet" <(E-Mail Removed)> skrev i melding
news:44744c70$0$31637$(E-Mail Removed)4all.nl...
> "Dag Sunde" <(E-Mail Removed)> wrote in message
> news:44743af5$(E-Mail Removed)...
>>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?

> *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..
>


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...

--
Dag.


 
Reply With Quote
 
Dag Sunde
Guest
Posts: n/a
 
      05-24-2006
"Dag Sunde" <(E-Mail Removed)> skrev i melding
news:44745692$(E-Mail Removed)...
> "Remon van Vliet" <(E-Mail Removed)> skrev i melding
> news:44744c70$0$31637$(E-Mail Removed)4all.nl...

<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
>> 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..
>>

>
> 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?
>

Belay that question...

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

Thanks!

--
Dag.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method for intracardiac therapy using sensor for heart wall thickness Barathi Java 0 01-25-2008 06:17 AM
method for intracardiac therapy using sensor for heart wall thickness Barathi Computer Support 0 01-25-2008 06:12 AM
button with runat = server changes its border thickness PJ6 ASP .Net 2 10-11-2005 01:29 AM
How set border thickness of table? VB Programmer ASP .Net 4 12-15-2004 05:16 PM
TableCellRenderer too slow??? Peter Java 2 08-07-2003 10:59 AM



Advertisments