Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JComboBox max caracters

Status
Not open for further replies.

haux

Programmer
Apr 11, 2001
79
DZ
How to fixe the maximum of characters that a JComboBox can hold.
So if i fixed it to3 when i tape the 4th character it's not echoed.

thanks for all ;-)
 
I don't think a JComboBox can be explicitly set to only display a certain number of characters. By default it is large enough to display the largest item contained within.

You may instead have to play around with the methods inherited from JComponent

setMaximumSize(Dimension d);
setMinimumSize(Dimension d);
setPreferredSize(Dimension d);

This may be your only option, although it is a pain in the arse to use if you want portability because Java appears to have different display configurations in windows and linux platforms for example.

I usually get around this by creating a Dimension object that is calculated as a percentage of screen space rather than an absolute pixel value.

If anyone knows different, I would appreciate the knowledge as well.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top