How to keep the highlight border of a JComponent, when custom border is set
        Posted  
        
            by Frederik Wordenskjold
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Frederik Wordenskjold
        
        
        
        Published on 2010-06-07T19:03:57Z
        Indexed on 
            2010/06/07
            19:12 UTC
        
        
        Read the original article
        Hit count: 511
        
I have a JTextField, where I've set some custom properties:
nameField.setPreferredSize(new Dimension(275,40));
nameField.setBackground(bgColor);
nameField.setForeground(txtColor);
nameField.setFont(new Font("HelveticaNeue",Font.PLAIN,22));
nameField.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
When the component has focus, there is no highlight shown around the field. On a Mac, it is usually a blue glowing rectangle, indicating that this component has focus.
If I comment out the nameField.setBorder(...), the highlight reappears. How do I keep the highlight, but also my custom border!?
Basically, I just want the highlight-border to show when the component has focus, and no border when the component is unfocused.
© Stack Overflow or respective owner