netbeans:如何在标题栏中添加一些标题

Jam*_*ame 6 java netbeans

我在Net Beans开发了一个小型桌面应用程序.当我运行我的应用程序时,Windows标题栏中没有标题.无论如何我通过它指定一些标题,稍后将出现在Windows标题栏中?以下是我的主要方法

public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MyJFrame().setVisible(true);
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

Var*_*mar 5

在 JFrame Netbeans Swing 中设置标题

您可以在属性窗口(右下角)中看到标题属性。您可以在单击该属性时设置标题。如果您找不到属性窗口,只需单击“设计”选项卡,然后单击空白的 JFrame GUI。


Pra*_*tik 3

您可以在 JFrame 初始化时设置标题栏,如下所示

JFrame frame = new JFrame("My Title");
Run Code Online (Sandbox Code Playgroud)

或者您可以为自定义类创建公共方法,例如

public void setTitle(String title){
    frame.setTitle(title); // for this you have declare the frame object as global for this class only
}
Run Code Online (Sandbox Code Playgroud)

并像这样使用

MyJFrame myframe = new MyJFrame();
myframe.setTitle("my new title");
myframe.setVisible(true);
Run Code Online (Sandbox Code Playgroud)