netbeans:如何在标题栏中放置一些标题

问题描述:

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

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

      public void run() { 
       new MyJFrame().setVisible(true); 
      } 
     }); 
    } 
+0

什么是MyJPane()? – Pratik

+0

@Pratik:用于创建UI,我首先添加JFrame,然后拖放所有控件 public class MyJPane extends javax.swing.JFrame {。 。 。 } – Jame

您可以设置JFrame的初始化时的标题栏这样

JFrame frame = new JFrame("My Title"); 

,或者你可以创建public方法你定制类如

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

,并使用像这样

MyJFrame myframe = new MyJFrame(); 
myframe.setTitle("my new title"); 
myframe.setVisible(true); 

myTopLevelContainer = new myTopLevelContainer("myTitlaLabel"); 

myTopLevelContainer.setTitle("myTitlaLabel"); 
+0

什么是myTopLevelContainer? – Jame

+0

@Jame'JFrame','JDialog'或(来自last milenium的非常古老的AWT组件)框架和对话框,更多关于*容器http://download.oracle.com/javase/tutorial/uiswing/components/toplevel.html – mKorbel

NetBeans Wiki

为了让您的应用程序标题,右键单击JFrame中,并打开其属性对话框。点击属性标签。

在Properties选项卡下,找到并修改title字段。 NetBeans将完成剩下的工作。

好了,这个工作对我来说...

public yourGUIname() { 
    initComponents(); 
    this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("your image here"))); 
    this.setTitle("your title here"); // that is the code you looking for 
} 

所以我所做的就是把上面的代码中产生的公共方法。

Setting title in JFrame Netbeans Swing

你可以看到在属性窗口标题属性(右下侧)。点击该属性即可设置标题。 如果您无法找到属性窗口,只需点击设计选项卡,然后点击空白的JFrame GUI。