Note that there are some explanatory texts on larger screens.

plurals
  1. POChange height of JCombobox
    primarykey
    data
    text
    <p>Is it possible to increase the height of a <code>JComboBox</code>?(not refering to the popup menu)</p> <p>Have tried:</p> <pre><code>comboBox.setPreferredSize(new Dimension(200, 100)); </code></pre> <p>and </p> <pre><code>Component[] comp = comboBox.getComponents(); for (int i = 0; i &lt; comp.length; i++) { if (comp[i] instanceof JButton) { JButton btn = (JButton) comp[i]; btn.setPreferredSize(new Dimension(200, 100)); } } </code></pre> <p>But no luck. Then I tried to fix the problem with layout managers:</p> <pre><code>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); </code></pre> <p>But this dose not seems to change the size of the <code>JComboBox</code> button.</p> <pre><code>public class ComboBoxFontChange extends JFrame { public ComboBoxFontChange() { // CREATE BOX JComboBox&lt;String&gt; cbox = new JComboBox&lt;String&gt;(); 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 &lt; 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); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload