且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Java 中创建自定义 JButton 类?

更新时间:2022-06-27 05:53:35

创建一个类并将其扩展到 JButton,如下所示,您可以在那里更改与 JButton 相关的所有类型.

create a class and extend it to JButton like below and there you can change all sort of things that has to do with JButton.

import javax.swing.JButton;

public class CustomJButton extends JButton {

    public CustomJButton() {
        this.setText("Custom JButton");
        // initialize
    }

    // add your own methods or override JButton methods
    public void myFunc(){

    }
}