Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 0.9.0
    • Fix Version/s: 0.9.2
    • Component/s: Table
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      716

      Description

      I'm trying to set custom rendering rules to a JXTable but I cannot make
      it work
      property.

      Env:

      • Windows XP SP2
      • JRE 1.6_02 Sun
      • swingx-2008_01_06.jar

      Code to reproduce the problem :


      class Test extends JFrame {
      public Test() {
      this.setLayout(new BorderLayout());

      JXTable table = new JXTable(new DefaultTableModel() {
      @Override
      public int getRowCount()

      { return 10; }

      @Override
      public int getColumnCount()

      { return 5; }

      @Override
      public Object getValueAt(int row, int column)

      { return row + ":" + column; }

      });

      table.getColumnModel().getColumn(0).setCellRenderer(
      new DefaultTableCellRenderer() {
      @Override
      public Component getTableCellRendererComponent(
      JTable table, Object value, boolean
      isSelected,
      boolean hasFocus, int row, int column)

      { Component result = super .getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); result .setBackground(new Color(255 - row * 10, 255, 255)); result.setForeground(new Color(20 * row, 20 * row, 20 * row)); return result; }

      });

      table.getColumnModel().getColumn(1).setCellRenderer(
      new DefaultTableCellRenderer() {
      @Override
      public Component getTableCellRendererComponent(
      JTable table, Object value, boolean
      isSelected,
      boolean hasFocus, int row, int column)

      { Component result = super .getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); result.setBackground(Color.yellow); result.setForeground(Color.red); return result; }

      });

      this.add(table, BorderLayout.CENTER);

      this.setSize(400, 200);
      this.setLocationRelativeTo(null);
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }

      public static void main(String[] args) throws Exception {
      UIManager.setLookAndFeel(new SubstanceLookAndFeel());
      SwingUtilities.invokeLater(new Runnable() {
      public void run()

      { new Test().setVisible(true); }

      });
      }

      }

      ------

      Result : no color background applied on column 0, see attached screenshot 1.
      However, the same code works perfectly for raw JTable widgets (see screenshot 2)

      Thanks,

      Bertrand Florat

        Activity

        Hide
        bflorat added a comment -

        Created an attachment (id=211)
        Screesnhot 1 : with JXTable

        Show
        bflorat added a comment - Created an attachment (id=211) Screesnhot 1 : with JXTable
        Hide
        bflorat added a comment -

        Created an attachment (id=212)
        Screenshot 2: with JTable

        Show
        bflorat added a comment - Created an attachment (id=212) Screenshot 2: with JTable
        Hide
        kirillcool added a comment -

        I just want to note that the same behavior is observed under Metal. Just remove
        the first line from the main() method.

        Kirill

        Show
        kirillcool added a comment - I just want to note that the same behavior is observed under Metal. Just remove the first line from the main() method. Kirill
        Hide
        bflorat added a comment -

        Yes, sorry, I forget to remove this line. The problem is not related with
        Substance LAF in any way.

        Show
        bflorat added a comment - Yes, sorry, I forget to remove this line. The problem is not related with Substance LAF in any way.
        Hide
        kleopatra added a comment -

        not a bug, it's a feature

        The bottom line is to not use renderer based visual modification in SwingX,
        that's what Highlighters are for. If you insist to do it on the renderer level,
        then don't use DefaultTableCellRenderer subclasses, they don't play nicely with
        Highlighters (see the api doc for prepareRenderer and the SwingX wiki for
        further details). If you are sure you don't want to use highlighters, you can
        turn off table's best efforts to tame DTCR by:

        table.putClientProperty(JXTable.USE_DTCR_COLORMEMORY_HACK, null);

        Jeanette

        Show
        kleopatra added a comment - not a bug, it's a feature The bottom line is to not use renderer based visual modification in SwingX, that's what Highlighters are for. If you insist to do it on the renderer level, then don't use DefaultTableCellRenderer subclasses, they don't play nicely with Highlighters (see the api doc for prepareRenderer and the SwingX wiki for further details). If you are sure you don't want to use highlighters, you can turn off table's best efforts to tame DTCR by: table.putClientProperty(JXTable.USE_DTCR_COLORMEMORY_HACK, null); Jeanette
        Hide
        kleopatra added a comment -

        > not a bug, it's a feature

        maybe too flappy: the bug is in DTCR (it has "color memomry"), the feature is
        that JXTable goes to great length to work around that bug (because there are so
        many DTCRs out in the wild). In the general case, it can do nothing if the
        renderer decides to set any color/s itself. The only option then is to disable
        the workaround.

        Show
        kleopatra added a comment - > not a bug, it's a feature maybe too flappy: the bug is in DTCR (it has "color memomry"), the feature is that JXTable goes to great length to work around that bug (because there are so many DTCRs out in the wild). In the general case, it can do nothing if the renderer decides to set any color/s itself. The only option then is to disable the workaround.

          People

          • Assignee:
            kleopatra
            Reporter:
            bflorat
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: