JDK-6505565 : GTK LF - combo boxes with custom renderer doesn't have border and correct size
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u2,7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2006-12-18
  • Updated: 2011-03-07
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b10Fixed
Related Reports
Duplicate :  
Description
There are visual problems with custom renderers in combo boxes in GTK LF. Please try to run attached test app - when run in Metal LF, all three combo boxes look the same, as expected, even if there are various custom renderers set. However, in GTK there are missing borders and inaccurate sizes unless renderer implements UIResource, overrides getName and calls setName from getListCellRendererComponent method: 

To get the borders and size right, we need to do:

    private static class OKRenderer extends JLabel implements ListCellRenderer, UIResource  {
        
        public Component getListCellRendererComponent(
            JList list,
            Object value,
            int index,
            boolean isSelected,
            boolean cellHasFocus) {
            
            // #89393: GTK needs name to render cell renderer "natively"
            setName("ComboBox.listRenderer"); // NOI18N
                    
            ......  
            
            return this;                    
        }

        // #89393: GTK needs name to render cell renderer "natively"
        public String getName() {
            String name = super.getName();
            return name == null ? "ComboBox.renderer" : name;  // NOI18N
        }
        
    }

As we (in NetBeans) use combobox.setRenderer on many places, workarounding this issue will be relatively painful for us.

Comments
EVALUATION We should take into account that all CellRenderers implement ListCellRenderer interface and calculate the WidgetType in the GTKEngine and Instets in GTKStyle accordingly. One importatnt thing is that ComboBox renders it's cell using one CellRenderer for the drowdown list and the selected item in the combobox. We play with names in the code, and we shouldn't forget to reset the name in SynthComboBoxUI to separate the look.
22-01-2007

WORK AROUND To get the borders and size right, we need to do: private static class OKRenderer extends JLabel implements ListCellRenderer, UIResource { public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { // #89393: GTK needs name to render cell renderer "natively" setName("ComboBox.listRenderer"); // NOI18N ...... return this; } // #89393: GTK needs name to render cell renderer "natively" public String getName() { String name = super.getName(); return name == null ? "ComboBox.renderer" : name; // NOI18N } } *** (#1 of 1): [ UNSAVED ] ###@###.###
18-12-2006