Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a JComboBox editable without affecting its width

I have a JComboBox object in my JFrame which behaves exactly as expected. However, I'd like to make it editable so that users can input alternative values if necessary. Unfortunately, using setEditable(true) to enable editing causes its width to increase significantly. How can I allow editing of the JComboBox while keeping its width only as wide as the largest selectable item requires?

The JComboBox is in a JPanel with a FlowLayout, however I don't think this is relevant because changing the width of the JPanel does not affect the width of the JComboBox.

uneditable jComboBox editable jComboBox

like image 235
Altay_H Avatar asked Jul 15 '26 08:07

Altay_H


1 Answers

JComboBox@setPrototypeDisplayValue("XXXXXXXXXXXXXX")

like image 102
mKorbel Avatar answered Jul 17 '26 21:07

mKorbel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!