I have a JCombobox and I’m adding some items at runtime. Some of them are very long and my Jcombobox is growing very long too. It’s in a JPanel container with BoxLayout (PAGE_AXIS). I have no idea how to prevent growing…
I wonder there should be a property like overflow and in combobox item will be shown like “123…” if it’s “123456789”.
EDIT:
I read your answers, thank you very much. But the problem is that my JPanel can resize and I need to make it’s children always fill parent. So I cant set preferred size because my JPanel’s size can change at runtime.
And I also can’t set maximum size or use setPrototypeDisplayValue() because of the same reason.
I tried to use other layouts (GroupLayout, BorderLayout) but the result is the same.
I can post code if you want but I think it’s not necessary. Let me know if you need it anyway.
Just tried with JTextArea with single row instead of JCombobox. Result is the same. It’s growing when I type.
I solved similair issue by overrode JComboBox.setPrototypeDisplayValue()
and there are two ways (as mentioned @Stas) resize JComboBox or its derived Popup or both together