How to set the size on a JComboBox

A

Aaron Fude

Hi,

I would like to set the width of a JComboBox to the widest item that
it contains. How does one do that after all the items have been added
to the JComboBox?

Many thanks in advance,

Aaron
 
A

Andrew Thompson

...
I would like to set the width of a JComboBox to the widest item that
it contains.

<sscce>
import javax.swing.*;

class ComboWidthTest {

public static void main(String[] args) {
String[] items = {
"a",
"b",
"c",
"dddddddddddddddddddddddddddddddddddddd",
"e"
};
JComboBox combo = new JComboBox(items);
JOptionPane.showMessageDialog(null, combo);
}
}
..How does one do that after all the items have been added
to the JComboBox?

It is usually automatic, unless any of
a number of silly things have been done
by one in the code that one is asking us
to guess about.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top