This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 212297 - Small height of encoding combo box in New project dialog
Summary: Small height of encoding combo box in New project dialog
Status: RESOLVED WONTFIX
Alias: None
Product: projects
Classification: Unclassified
Component: Generic Projects UI (show other bugs)
Version: 7.2
Hardware: PC Linux
: P3 normal (vote)
Assignee: Tomas Stupka
URL:
Keywords: API, L&F
Depends on: 91338
Blocks: 93658 182711
  Show dependency tree
 
Reported: 2012-05-10 10:34 UTC by Vladimir Riha
Modified: 2016-07-07 08:37 UTC (History)
5 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
screenshot (56.29 KB, image/png)
2012-05-10 10:34 UTC, Vladimir Riha
Details
The many looks of a combo box (19.40 KB, image/png)
2012-05-11 15:43 UTC, Jesse Glick
Details
Initial patch for feedback (25.79 KB, patch)
2012-05-11 22:25 UTC, Jesse Glick
Details | Diff
Demonstration of using original renderer (2.15 KB, text/x-java)
2012-05-31 23:38 UTC, Jesse Glick
Details
Reworked patch, no Renderers, API changes in projectuiapi & java.api.common (24.76 KB, patch)
2012-06-12 21:35 UTC, Jesse Glick
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Riha 2012-05-10 10:34:26 UTC
Created attachment 119273 [details]
screenshot

Check the screenshot, under Ubuntu & GTK+ the height of the 2nd combo box is small



Product Version: NetBeans IDE Dev (Build 201205100400)
Java: 1.7.0_04; Java HotSpot(TM) Client VM 23.0-b21
System: Linux version 3.0.0-19-generic-pae running on i386; UTF-8; en_US (nb)
Comment 1 Vladimir Riha 2012-05-10 11:59:33 UTC
the same in project properties dialog in Sources, again for encoding...
Comment 2 Tomas Mysik 2012-05-11 05:18:38 UTC
PHP uses ProjectCustomizer.encodingRenderer() from Project UI API.

Please evaluate, thanks.
Comment 3 Jesse Glick 2012-05-11 15:43:56 UTC
Created attachment 119361 [details]
The many looks of a combo box

Shows what a non-editable JComboBox looks like in various places. All taken using JDK 6u32 on Ubuntu 12.04 with GNOME 3 Shell in GTK L&F.

1. Two combo boxes from a j2seproject's Sources tab.
2. From the Run tab.
3. From the Formatting tab.
4. A plain combo box with no special renderer or other code in a sample app.
Comment 4 Jesse Glick 2012-05-11 16:53:13 UTC
My experiments suggest that there is just no reasonable way to make a JComboBox with a nontrivial custom model - one in which toString() is not the appropriate conversion for model elements - to look right when creating a ListCellRenderer out of context, the way our current helper APIs (such as ProjectCustomizer.encodingRenderer) do. The one thing that _does_ seem to work is to delegate to the original renderer installed by the L&F:

final ListCellRenderer orig = combo.getRenderer();
combo.setRenderer(new ListCellRenderer() {
  public Component getListCellRendererComponent(JList l, Object v, int i, boolean sel, boolean foc) {
    return orig.getListCellRendererComponent(l, "* " + v, i, sel, foc);
  }
});

The one drawback I can see here is that (since this is not a UIResource) if the L&F changes, the combo will still be displayed in the original delegate. I do not think this matters for usage in NetBeans, since we do not change L&F on the fly (and I hope GTK L&F when responding to GNOME theme changes does not set a new renderer but just adjusts the behavior of the existing one).

The next question is compatibility - whether it is possible to find the original renderer (or an equivalent) given the JComboBox on which setRenderer has already been set.

PlatformUiSupport.createSourceLevelListCellRenderer is a special hurdle because it delegates to HtmlRenderer.createRenderer() to highlight unsupported values, and thus looks wrong in a different way than all the rest (first combo in screenshot).
Comment 5 Jesse Glick 2012-05-11 18:46:25 UTC
(In reply to comment #4)
> find the original renderer given the JComboBox on which setRenderer was set

It would be, with some reflection and such tricks. But even that information is not available inside getListCellRendererComponent: the renderer is only given the JList which is held in the BasicComboPopup. So we need to look for UI default ComboBoxUI subclass, and then try to construct it directly rather than calling createUI. Even that does not work for SynthLookAndFeel, which returns itself rather than SynthComboBoxUI as expected. Tricky.
Comment 6 Jesse Glick 2012-05-11 22:25:52 UTC
Created attachment 119375 [details]
Initial patch for feedback

Fixes problems observable in j2seproject Properties dialog under GTK. Need to check other project types and forms, and confirm that everything looks normal on other L&Fs.
Comment 7 Jesse Glick 2012-05-11 22:28:31 UTC
apichanges and more to come, but I would like to start getting feedback on this. Was the approach I have taken considered in the past and rejected, or it just was not discovered yet?


Not clear to me if defaultComboBoxRenderer() as written is the best approach, or if I should just use e.g.

ListCellRenderer r = new JComboBox().getRenderer();
return r != null ? r : new BasicComboBoxRenderer.UIResource();
Comment 8 Stanislav Aubrecht 2012-05-14 09:38:04 UTC
(In reply to comment #7)

> 
> ListCellRenderer r = new JComboBox().getRenderer();
> return r != null ? r : new BasicComboBoxRenderer.UIResource();
This looks better to me - but I haven't tried if it actually works...


There might be another problem when switching L&F at runtime. L&f-native renderers tend to cast various objects to their expected l&f subclasses. The combo box should actually override updateUI() method to set the renderer.
Comment 9 Jesse Glick 2012-05-14 19:30:22 UTC
(In reply to comment #4)
> PlatformUiSupport.createSourceLevelListCellRenderer is a special hurdle because
> it delegates to HtmlRenderer.createRenderer() to highlight unsupported values,
> and thus looks wrong in a different way than all the rest

Note that the current patch avoids the issue by using the delegate for regular values ("JDK 6"), only using the problematic HTML renderer for broken values ("Broken platform: 1.7"). I have no idea how HtmlRenderer could be used in such a way as to look just like the native renderer for text that happens to contain no markup.

(In reply to comment #7)
> Not clear to me if defaultComboBoxRenderer() as written is the best approach

...or another alternative is to not introduce Renderers at all, but rather deprecate existing API methods like ProjectCustomizer.encodingRenderer in favor of overloads which take an original renderer. This would make for a somewhat bigger API change but might be considered cleaner.

(In reply to comment #8)
> There might be another problem when switching L&F at runtime.

Is this an issue for NetBeans code? We provide no UI control to switch L&F dynamically.

> The combo box should actually override updateUI() method to set the renderer.

Definitely this would be more cumbersome for callers - typically Matisse-built forms, which would need custom initialization code to create an anonymous JComboBox subclass.
Comment 10 Stanislav Aubrecht 2012-05-15 10:28:24 UTC
(In reply to comment #9)
> (In reply to comment #8)
> > There might be another problem when switching L&F at runtime.
> 
> Is this an issue for NetBeans code? We provide no UI control to switch L&F
> dynamically.
On Windows it is possible to switch to 'windows classic' appearance and back to 'windows vista/7' look. But it's not a frequent operation I'd guess.

> 
> > The combo box should actually override updateUI() method to set the renderer.
> 
> Definitely this would be more cumbersome for callers - typically Matisse-built
> forms, which would need custom initialization code to create an anonymous
> JComboBox subclass.
Sure, I was just thinking we could override updateUI() of combo boxes at well known screens in NetBeans, e.g. project properties window.
Comment 11 Jesse Glick 2012-05-15 11:49:23 UTC
(In reply to comment #10)
> On Windows it is possible to switch to 'windows classic' appearance and back to
> 'windows vista/7' look.

Right, but will these operations actually update Swing UI delegates, or merely alter the behavior of the existing WindowsLookAndFeel? I can try to find a working version of Vista to check.
Comment 12 Stanislav Aubrecht 2012-05-15 12:48:12 UTC
(In reply to comment #11)
> (In reply to comment #10)
> > On Windows it is possible to switch to 'windows classic' appearance and back to
> > 'windows vista/7' look.
> 
> Right, but will these operations actually update Swing UI delegates, or merely
> alter the behavior of the existing WindowsLookAndFeel? I can try to find a
> working version of Vista to check.

Yes, updateUI() is called when switching to/from Windows Classic appearance. We install new UI delegates for window tabs during that time.
Comment 13 Jesse Glick 2012-05-31 23:12:09 UTC
(In reply to comment #4)
> final ListCellRenderer orig = combo.getRenderer();
> combo.setRenderer(new ListCellRenderer() {
>   public Component getListCellRendererComponent(JList l, Object v, int i,
> boolean sel, boolean foc) {
>     return orig.getListCellRendererComponent(l, "* " + v, i, sel, foc);
>   }
> });

Another problem is that the above code does not type well in JDK 7 - cannot be written without @SuppressWarnings("unchecked"). Which I guess is a logical flaw in Swing - for a JComboBox<Integer>, getRenderer() returns ListCellRender<? super Integer>, but in fact the default renderer can render any Object since it just calls toString(), and you _need_ it to render String.
Comment 14 Jesse Glick 2012-05-31 23:38:44 UTC
Created attachment 120171 [details]
Demonstration of using original renderer

Apparently contrary to comment #10, this seems to work in XP even switching between "Windows Classic" and "Windows XP" themes.
Comment 15 Jesse Glick 2012-06-12 21:35:55 UTC
Created attachment 120753 [details]
Reworked patch, no Renderers, API changes in projectuiapi & java.api.common

More straightforward patch. Missing apichanges/versioning, and missing usages in various other project types, but demonstrates the concept.
Comment 16 Jesse Glick 2012-06-12 21:36:49 UTC
Withdrawing from API review in 7.2; just did not have enough time to review and test properly.
Comment 17 Martin Balin 2016-07-07 08:37:59 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss