开发者

Set the height of an item inside a JCombobox

开发者 https://www.devze.com 2023-03-17 17:53 出处:网络
I have a JCombobox with many items and first of all them is a NULL value When opening the combobox, all the items have a normal height but not the first one which is a really thin strip at the top of

I have a JCombobox with many items and first of all them is a NULL value

When opening the combobox, all the items have a normal height but not the first one which is a really thin strip at the top of all. That makes really difficult to be clickable since it looks like the开发者_如何学运维re is nothing (but it is there and you can select it).

The question is, how can I make this item to have the same height than the other items?

More information:

  • I have tried with JCombobox.setPrototypeDisplayValue() with a normal String like "XXXXX" or with one of the normal items, but that changes the width but not the height.
  • The null value is represented in the JCombobox with an empty String ("") via a ObjectToStringConverter subclass:

org.jdesktop.swingx.autocomplete.AutoCompleteDecorator.decorate (combobox, ConfigurableToStringConverter.INSTANCE);

Thanks in advance


Override the default renderer used for comboboxes (see DefaultListCellRenderer class). Check the getListCellRendererComponent() method. Call super.getListCellRendererComponent() and if value is NULL set empty string (or space char string " ") as the value.


Looking at camickr's Combo Box Popup, the code source shows setPreferredSize for Width, but I can't see any reason not to use setPreferredSize for Height the same way.

There is only question is if there may be some conflict between SwingX#AutoCompleteDecorator and standard Swing code

0

精彩评论

暂无评论...
验证码 换一张
取 消