如何删除 JButton 中文本周围的蓝线? - Java

How do I remove the blue line around the text in a JButton? - Java

我有一个 JButton 这样的:

JButton button = new JButton("ExampleText") {
    private static final long serialVersionUID = 1L;
    {   
        setBackground(Color.LIGHT_GRAY);
        setBorder(new LineBorder(Color.GRAY, 2));
    }
};

它看起来像这样:

如您所见,文本周围有一种蓝色边框。我怎样才能删除它?

使用setFocusPainted:

button.setFocusPainted(false);