Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6888156

With GTK Look and Feel Icons cannot be rendered in Jtable Cells

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 6u16
    • Fix Version/s: 7
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b78
    • CPU:
      x86
    • OS:
      linux_ubuntu

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_16"
      Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
      Java HotSpot(TM) Server VM (build 14.2-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux matt-laptop 2.6.28-11-generic #42-Ubuntu SMP Fri Apr 17 01:57:59 UTC 2009 i686 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      I have a JTable with a model attached that returns cells with a Icon in on column 0.
      The table is attached to a AbstractTableModel that overrides getColumnClass to return Icon.class for column zero.
          @Override
          public Class<?> getColumnClass(int columnIndex) {
              switch (columnIndex) {
                  case 0:
                      return Icon.class;
              }
              return super.getColumnClass(columnIndex);
          }

      This correctly displays the icon in the cell when running on Windows with system UI.

      When running on Linux, system UI look and feel or GTK Look ad Feel, then you get a null pointer exception:

      Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
              at javax.swing.JTable.prepareRenderer(JTable.java:5729)
              at javax.swing.plaf.synth.SynthTableUI.paintCell(SynthTableUI.java:622)
              at javax.swing.plaf.synth.SynthTableUI.paintCells(SynthTableUI.java:519)
              at javax.swing.plaf.synth.SynthTableUI.paint(SynthTableUI.java:308)
              at javax.swing.plaf.synth.SynthTableUI.update(SynthTableUI.java:234)
              at javax.swing.JComponent.paintComponent(JComponent.java:763)


      I delved into the code and SynthTableUI is used on gtk and not on windows.

      In SynthTableUI, the paintcell tries to find a cell renderer and eventually ends up looking in defaultRenderersByColumnClass variable. On windows this has 8 elements in it corresponding to the default editors for boolean, icon, float etc.

      However, when SynthTableUI is used, defaultRenderersByColumnClass has the 8 elements until JTable.UpdateUI calls setUI((TableUI)UIManager.getUI(this));

      Eventually this calls SynthTableUI.installDefaults which does not seem to install defaults ...

          protected void installDefaults() {
              dateRenderer = installRendererIfPossible(Date.class, null);
              numberRenderer = installRendererIfPossible(Number.class, null);
              doubleRender = installRendererIfPossible(Double.class, null);
              floatRenderer = installRendererIfPossible(Float.class, null);
              iconRenderer = installRendererIfPossible(Icon.class, null);
              imageIconRenderer = installRendererIfPossible(ImageIcon.class, null);
              booleanRenderer = installRendererIfPossible(Boolean.class,
                                       new SynthBooleanTableCellRenderer());
              objectRenderer = installRendererIfPossible(Object.class,
                                              new SynthTableCellRenderer());
              updateStyle(table);
          }

      It attempts to install null renderers for each item, eventually calling jtable.setDefaultRenderer and passign in the null which removes it from the defaults.

      As opposed to uninstall which seems to install them!

          protected void uninstallDefaults() {
              table.setDefaultRenderer(Date.class, dateRenderer);
              table.setDefaultRenderer(Number.class, numberRenderer);
              table.setDefaultRenderer(Double.class, doubleRender);
              table.setDefaultRenderer(Float.class, floatRenderer);
              table.setDefaultRenderer(Icon.class, iconRenderer);
              table.setDefaultRenderer(ImageIcon.class, imageIconRenderer);
              table.setDefaultRenderer(Boolean.class, booleanRenderer);
              table.setDefaultRenderer(Object.class, objectRenderer);

      if (table.getTransferHandler() instanceof UIResource) {
      table.setTransferHandler(null);
      }
              SynthContext context = getContext(table, ENABLED);
              style.uninstallDefaults(context);
              context.dispose();
              style = null;
          }
         



      REPRODUCIBILITY :
      This bug can be reproduced always.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                peterz Peter Zhelezniakov (Inactive)
                Reporter:
                ndcosta Nelson Dcosta
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: