Border thickness in TableCellRenderer too thick...

Discussion in 'Java' started by Dag Sunde, May 24, 2006.

  1. Dag Sunde

    Dag Sunde Guest

    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.
     
    Dag Sunde, May 24, 2006
    #1
    1. Advertising

  2. "Dag Sunde" <> wrote in message
    news:44743af5$...
    >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
     
    Remon van Vliet, May 24, 2006
    #2
    1. Advertising

  3. Dag Sunde

    Dag Sunde Guest

    "Remon van Vliet" <> skrev i melding
    news:44744c70$0$31637$4all.nl...
    > "Dag Sunde" <> wrote in message
    > news:44743af5$...
    >>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.
     
    Dag Sunde, May 24, 2006
    #3
  4. Dag Sunde

    Dag Sunde Guest

    "Dag Sunde" <> skrev i melding
    news:44745692$...
    > "Remon van Vliet" <> skrev i melding
    > news:44744c70$0$31637$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.
     
    Dag Sunde, May 24, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer

    How set border thickness of table?

    VB Programmer, Dec 15, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    935
    bruce barker
    Dec 15, 2004
  2. tshad
    Replies:
    0
    Views:
    2,304
    tshad
    Jan 31, 2005
  3. PJ6
    Replies:
    2
    Views:
    480
  4. Peter
    Replies:
    2
    Views:
    767
    Cyril Mrazek
    Aug 7, 2003
  5. phl
    Replies:
    1
    Views:
    4,415
    Martin Jay
    Jun 8, 2006
Loading...

Share This Page