jtable text size

Discussion in 'Java' started by tiewknvc9, Nov 29, 2005.

  1. tiewknvc9

    tiewknvc9 Guest

    Hi!

    Im working with an extended jtable, in the constructor, I set the font
    size and the rowHeight,

    htfFont = new Font("Courier", Font.PLAIN, 15);
    this.setFont(htfFont);
    this.setRowHeight(htfFont.getSize() + 3);

    the font seems to only take effect after exiting the cell, when it is
    being editted it looks quite small. I would expect that there should be
    an easy way to do this rather than creating a new tablecelleditor and
    tablecellrenderer classes.. and ideas?

    thanks
    tiewknvc9, Nov 29, 2005
    #1
    1. Advertising

  2. tiewknvc9

    zero Guest

    "tiewknvc9" <> wrote in news:1133274793.353121.112970
    @o13g2000cwo.googlegroups.com:

    > Hi!
    >
    > Im working with an extended jtable, in the constructor, I set the font
    > size and the rowHeight,
    >
    > htfFont = new Font("Courier", Font.PLAIN, 15);
    > this.setFont(htfFont);
    > this.setRowHeight(htfFont.getSize() + 3);
    >
    > the font seems to only take effect after exiting the cell, when it is
    > being editted it looks quite small. I would expect that there should be
    > an easy way to do this rather than creating a new tablecelleditor and
    > tablecellrenderer classes.. and ideas?
    >
    > thanks
    >


    If I'm not mistaken (but don't shoot me if I am) the default cell renderer
    for plain text is a JLabel (or a subclass of it), and the editor is a
    JTextField (again, or a subclass). If that is indeed so, you could
    override JTable:getCellRenderer and JTable:getCellEditor - you wouldn't
    need to create your own renderer/editor.

    public TableCellRenderer getCellRenderer(...)
    {
    TableCellRenderer renderer = super.getCellRenderer(..);
    renderer.setFont(new Font(...));
    return renderer;
    }

    Without looking at the JTable source I'm not sure if you should override
    getRowHeight as well. I'm guessing no, it probably just returns the height
    of the heighest component in the row.

    --
    Beware the False Authority Syndrome
    zero, Nov 29, 2005
    #2
    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. Tivo Escobar
    Replies:
    1
    Views:
    7,307
    manusa
    Apr 12, 2007
  2. Yulia
    Replies:
    1
    Views:
    669
    Andrew Thompson
    Jul 4, 2005
  3. Tintin92
    Replies:
    1
    Views:
    1,693
    Andrew Thompson
    Feb 14, 2007
  4. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,556
    Michael Jung
    May 25, 2008
  5. Haircuts Are Important
    Replies:
    3
    Views:
    312
    Haircuts Are Important
    Jun 4, 2013
Loading...

Share This Page