Results 1 to 4 of 4
  1. #1
    Ralphw is offline Member
    Join Date
    Feb 2009
    Posts
    9
    Rep Power
    0

    Default TableRowSorter, HeaderRenderer and LAF

    Hi *

    Assume there is a Jtable that user the TableRowSorter.
    If there is the LAF set as
    Java Code:
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    the Table Header get the sorting Icon (up/Down)
    A kind of underlining Border for XPStyle is displayed if the HeaderCell gets the focus.
    Now i want to have my own HeaderCellRenderer for Multiple lines.

    i created a class:
    Java Code:
    class DefaultSwingTableHeaderRenderer extends JPanel implements
          TableCellRenderer
    and added a Label to the Panel of the renderer
    Java Code:
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column)
        {
          Component c = defaultRenderer.getTableCellRendererComponent(table, value,
              isSelected, hasFocus, row, column);
    
    if (c instanceof JLabel)
          {
            JLabel label = (JLabel) c;
            this.mark = (Icon) label.getIcon();
            removeAll();
    ...
    ...
    ....
    String[] header = ((String) value).split("\n");
                setLayout(new GridLayout(header.length, 1));
                for(String s: header){
                  label1 = new JLabel(s,(Icon) this.mark,JLabel.CENTER);
                  label1.setHorizontalTextPosition(JLabel.LEFT);
                  add(label1);
                }
    But now i have to handle the Icon and i loose the functionalitiy of the focus
    - no underlining Border (orange for XPStyle)
    - no background Color change if cell is focused

    If i debug the defaultRenderer.getTableCellRendererComponent i get the
    WindowsTableHeaderUI.XPDefaultRenderer method that is private.

    What method constructs the "orange Border" ?

    Any Ideas to solve this Problem. ?

  2. #2
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    As far as I can understand the code,
    it gets a JLabel from getTableCellRendererComponent
    and then replaces that JLabel with a new one.
    This could indeed lose the focus information that was passed along with hasFocus.
    The JLabel code is responsible for painting the orange.

    Why replace the JLabel?
    Why not just modify the JLabel returned by getTableCellRendererComponent?

  3. #3
    Ralphw is offline Member
    Join Date
    Feb 2009
    Posts
    9
    Rep Power
    0

    Default

    This is what i tried:
    modify the label by given a text as html code with <BR> that gives me two lines.
    Then i run into the problem that the column heigth does not fit anymore.
    Of course i can modify the column attributes, but i am looking for an easier solution. Maybe there is not one

  4. #4
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    Calling invalidate() on the appropriate Component may help.

Similar Threads

  1. Replies: 6
    Last Post: 02-20-2009, 11:03 AM
  2. Jtable + TableRowSorter
    By Ralphw in forum AWT / Swing
    Replies: 8
    Last Post: 02-05-2009, 10:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •