I have a JComboBox where i use the method setPrototypeDisplayValue to make it wide enough for the combobox to display the whole value of the widest value.
Gui.form
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="gui.Gui">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="313" y="137" width="252" height="86"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="2aff5" class="javax.swing.JComboBox" binding="comboBox">
<constraints>
<grid row="0" column="0" row-span="2" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="1" use-parent-layout="false">
<minimum-size width="150" height="24"/>
<preferred-size width="180" height="24"/>
</grid>
</constraints>
<properties>
<foreground color="-16777216"/>
<maximumRowCount value="2"/>
<model>
<item value="stringOfLengthEqualTo23"/>
<item value="stringOfLengthEqualTo23"/>
<item value="stringOfLengthGreaterThan23"/>
</model>
</properties>
</component>
</children>
</grid>
</form>
Gui.java
package gui;
import javax.swing.*;
public class Gui {
private JComboBox<String> comboBox;
private JPanel panel;
public Gui(){
initComponents();
}
public void initComponents(){
comboBox = new JComboBox();
comboBox.setMaximumRowCount(2); //max row count is 2
comboBox.setMinimumSize(new java.awt.Dimension(150, 24));
comboBox.setName("connectedHardwareTool"); // NOI18N
comboBox.setPreferredSize(new java.awt.Dimension(180, 24));
comboBox.setPrototypeDisplayValue("stringOfLengthGreaterThan23");
}
public static void main(String[] args){
JFrame frame = new JFrame();
frame.setContentPane(new Gui().panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
maxRowCount is set to 2 if 3 tools are connected, the scrollbar comes into picture and the dropdown is not as wide as per the prototype value
Why is this happening?
P.S. I have tried extending the popupmenulistener to increase the width, when the pop up becomes visible but that gives a completely different issue that i don't want to get into now.