Results 1 to 4 of 4
  1. #1
    cjmartin is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default Need help with highlighting text in a jcombobox

    I have tried a few different ways to to highlight the text in a jcombobox when it receives focus but none have work. Any have a code example that could help?

    Some examples I have tried:

    Java Code:
    private void fromComboBoxFocusFocusGained(FocusEvent event) {
      JTextField field = (JTextField)fromComboBox.getEditor().getEditorComponent();
      field.selectAll();
            
    }
    Java Code:
    private void fromComboBoxFocusFocusGained(FocusEvent event) {
      fromComboBox.getEditor().selectAll();
    }
    Thanks for your help.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default

    Add the FocusListener to the JTextField, not to the JComboBox.

    db

  3. #3
    cjmartin is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default

    Darryl.Burke, I am not sure what you mean. I am needing to highlight the text on the combobox. The JTextField field that I have in my code was used to get the editor component of the combo. Can I just randomly add a action listener to that jtextfield inside of the focus gaines method of the combobox?

  4. #4
    cjmartin is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default

    I figured out my problem. The below code does work, I just didn't have it in all the necessary places. Thanks for your help.

    Java Code:
    	    		       				
    JTextField field = (JTextField)fromComboBox.getEditor().getEditorComponent();
    
    field.selectAll();

Similar Threads

  1. how unhighlight text in jcombobox?
    By pinks_70986 in forum New To Java
    Replies: 11
    Last Post: 06-01-2012, 01:13 PM
  2. Highlighting Multiple Selected Rows
    By bigj in forum New To Java
    Replies: 2
    Last Post: 02-07-2010, 05:31 PM
  3. Eclipse Syntax Highlighting
    By garrettgjb in forum Eclipse
    Replies: 1
    Last Post: 08-24-2009, 03:10 PM
  4. Replies: 1
    Last Post: 04-25-2009, 03:50 PM
  5. [SOLVED] Line Highlighting
    By Doctor Cactus in forum New To Java
    Replies: 2
    Last Post: 03-26-2009, 03:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •