Is it possible to increase the height of a JComboBox
?(not refering to the popup menu)
Have tried:
comboBox.setPreferredSize(new Dimension(200, 100));
and
Component[] comp = comboBox.getComponents();
for (int i = 0; i < comp.length; i++) {
if (comp[i] instanceof JButton) {
JButton btn = (JButton) comp[i];
btn.setPreferredSize(new Dimension(200, 100));
}
}
But no luck. Then I tried to fix the problem with layout managers:
JPanel panel = new JPanel(new GridBagLayout());
panel.setPreferredSize(new Dimension(100, 100));
GridBagConstraints c = new GridBagConstraints();
c.weighty = 1;
c.fill = GridBagConstraints.VERTICAL;
panel.add(cbox, c);
But this dose not seems to change the size of the JComboBox
button.
public class ComboBoxFontChange extends JFrame {
public ComboBoxFontChange() {
// CREATE BOX
JComboBox<String> cbox = new JComboBox<String>();
cbox.setFont(cbox.getFont().deriveFont(30.0f));
// TRY CHANGE SIZE: DOSE NOT WORK..
cbox.setPreferredSize(new Dimension(200, 100));
cbox.setSize(new Dimension(200, 100));
cbox.setMinimumSize(new Dimension(200, 100));
// TRY CHANGE SIZE ON BUTTON INSTEAD: DOSE NOT WORK..
Component[] comp = cbox.getComponents();
for (int i = 0; i < comp.length; i++) {
if (comp[i] instanceof JButton) {
JButton btn = (JButton) comp[i];
btn.setPreferredSize(new Dimension(200, 100));
btn.setSize(new Dimension(200, 100));
btn.setMinimumSize(new Dimension(200, 100));
}
}
cbox.addItem("Quarter");
cbox.addItem("Nickel");
cbox.addItem("Penny");
JPanel panel = new JPanel();
panel.add(cbox);
getContentPane().add(panel);
}
public static void main(String[] args) {
ComboBoxFontChange frame = new ComboBoxFontChange();
frame.setSize(300, 150);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setVisible(true);
}
}