JComboBox text length limit

G

Guest

Is there a way to set an editable JComboBox to only allow one
character to be entered? I can do it in a JTextField by extending
PlainDocument and setting it to the document on the control but
JComboBox has no setDocument().
 
G

Guest

Is there a way to set an editable JComboBox to only allow one
character to be entered? I can do it in a JTextField by extending
PlainDocument and setting it to the document on the control but
JComboBox has no setDocument().

Sorted it. A JComboBox can be cast to a JTextField like this:

((JTextField) this.getEditor().getEditorComponent()).setDocument(new
JComboBoxLimitDoc(1));
 

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
473,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top