Re: Different height at JComboBox editor and renderer



bobjan wrote:
I want to use JComboBox to enabe user to select from a list of images.
I also want that after the selection is made, only the name associated
to the image is shown at JComboBox text field part(next to the button,
or the button itself if the combo box is uneditable).

I tried with custom ComboBoxEditor and ListCellRenderer, the renderer
to show images, and the editor to show the name.
It works, but I can not adjust different heights. When I specify the
"normal" text height at ListCellRenderer, the images shown are
narrowed. When I try with the image dimension, the name text is
extremly high. It seems that I can not have different heights of those
two JComboBox components. Is there a way I can accomplish this ?

I believe the problem is that combo box uses (possibly from the PL&F) the ListCellRenderer to paint the field when it is not being edited. What you need to do is return an appropriate component (e.g. the editor) from ListCellRenderer.getListCellRendererComponent when the index is -1.


Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
.


Quantcast