3 Replies Latest reply: May 15, 2012 12:58 AM by 937323 RSS

    Java Swing: JComboBox  setEditable(true)

    937323
      How to limit the length of the text in Jcombobox with seteditable true to 255 characters.So that user can't enter text more then 255 characters.
        • 1. Re: Java Swing: JComboBox  setEditable(true)
          StanislavL
          You can get editor from the JComboBox. In the editor get a text filed used for edit. You can cast it to JTextField in the simplest case. Then add a DocumentFilter to the JTextFiled's document. Override the methods to check existing Document's length and ignore edits when limit is achieved.
              public void insertString(FilterBypass fb, int offset, String string,
                                       AttributeSet attr) throws BadLocationException {
                  fb.insertString(offset, string, attr);
              }
          
              public void replace(FilterBypass fb, int offset, int length, String text,
                                  AttributeSet attrs) throws BadLocationException {
                  fb.replace(offset, length, text, attrs);
              }
          • 2. Re: Java Swing: JComboBox  setEditable(true)
            937323
            i didn't the solution yet. as i didn't get the anwser given by you. Can you give me the simple solution for this..
            • 3. Re: Java Swing: JComboBox  setEditable(true)
              937323
              Thanx i got the solution.