When I put a JComboBox into a JPanel with GridBagLayout, I find the longest JComboBox item will not fully show, instead, it show part of with ‘…’
For example, it show ‘Healthcare Ingred…’ for ‘Healthcare Ingredient’.
Please have a look at the screenshot here:

Code is something like this:
JPanel infoPanel = JPanel(new GridBagLayout());
dataTypeCB = new JComboBox(dataTypeList.toArray());
infoPanel.add(dataTypeCB, new GridBagConstraints(1, 1, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5,5,5,5), 0, 0));
I find out two solution already:
- overwrite the getPreferenceSize of JComboBox, however a bit annoying.
- wrap the JComboBox with a JPanel, like below, however the warpped JPanel introduce some intents and cause alignment issue instead, still not perfect:
code of second solution:
dataTypeCB = new JComboBox(dataTypeList.toArray());
JPanel dataTypeCBPanel = new JPanel();//make item can be fully show up.
dataTypeCBPanel.add(dataTypeCB, BorderLayout.CENTER);
infoPanel.add(dataTypeCBPanel, new GridBagConstraints(1, 1, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5,5,5,5), 0, 0));
My question is : is any other easy way to solve this issue?
Enviroment: windows 7 with JDK 1.6_25(64bit version)
Many Thanks
Solve this issue by myself.
The reason why I get this, is because I am using a library with the name “JIDE”, which bring its LookAndFeel into my application.
I tested on the JDK’s default look and feel, they looks do not have this issue.
Then I switch to JIDE’s look and Feel, then I can reproduce this issue.
So I think the problem is related with the LookAndFeel. The ComboBoxUI class.
So what I really need to do is to write my own ComboBoxUI or extends the UI class in JIDE library.
Sorry for did not give enough information for this, when I ask question, I did not realize it is related with the LookAndFeel.
Thanks