我试图让我的 JButton 在单击时停止其背景更改。我一直在阅读和其他测试回答问题,像这样的,但没有帮助我。我对 Java 很陌生,所以具体的细节会有所帮助,这是我的代码和正在发生的事情的演示。另外,如果这很重要,我正在运行 ubuntu。
注意:如果我按住鼠标并将鼠标悬停在它上面,它也会触发背景更改。
import javax.swing.*;
import java.awt.*;
public class RaisedButton extends JButton{
private String text = "";
private String type = "default";
public RaisedButton(String text, String type) {
this.text = text;
this.type = type;
__init__();
}
private void foundations() {
NotoFont noto = new NotoFont(true);
this.setText(this.text.toUpperCase());
this.setRolloverEnabled(false);
this.setFocusPainted(false);
this.setBorderPainted(false);
this.setFont(noto.get());
this.setPreferredSize(new Dimension(108 + this.text.length() * 4, 37));
}
private void default_type() {
this.foundations();
this.setBackground(Color.decode("#FFFFFFF"));
this.setForeground(Color.decode("#000000"));
}
private void primary_type() {
this.foundations();
this.setBackground(Color.decode("#00BCD4")); …Run Code Online (Sandbox Code Playgroud)