Border thickness in TableCellRenderer too thick...

D

Dag Sunde

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;
}
}
 
R

Remon van Vliet

Dag Sunde said:
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
 
D

Dag Sunde

Remon van Vliet said:
*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...
 
D

Dag Sunde

Dag Sunde said:
"Remon van Vliet" <[email protected]> skrev i melding


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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top