Search code examples
javatextjbuttonhighlight

How to remove textbox highlight on button click (Java)


The highlight to which I'm refering:

enter image description here

When i click on the JButton that uses following code:

    public static JButton addButton(JPanel panel, String text, Point pos, int width, int height, ActionListener action)
{
    JButton button = new JButton(text);
    button.setBounds(pos.x, pos.y, width, height);
    button.addActionListener(action);
    button.setVisible(true);
    button.setBackground(new Color(255, 137, 58));
    button.setForeground(Color.white);
    button.setBorder(new LineBorder(new Color(196, 96, 29), 2));
    button.setRolloverEnabled(true);
    panel.add(button, 3, 0);

    return button;
}

The textbox highlights afterwards. Is there a simple way to remove this effect?


Solution

  • Add this

    button.setFocusPainted(false);