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.
Note that the original border is of type com.apple.laf.AquaTextFieldBorder.
Basically, I just want the highlight-border to show when the component has focus, and no border when the component is unfocused.
The you need need to use a FocusListener. First you need to save the current Border. Then on focusLost you set the Border to null and on focusGained you use the saved Border.
Or you can get the default Border for the component by using the UIManager.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With