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

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top