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

GTK LF - combo boxes with custom renderer doesn't have border and correct size

XMLWordPrintable

    • b10
    • x86
    • linux
    • Verified

      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.

            stayer Kirill Kirichenko (Inactive)
            dsimoneksunw David Simonek (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: