2011-09-22 91 views
4

我在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

回答

3

您可以設置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); 
2
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

1

NetBeans Wiki

爲了讓您的應用程序標題,右鍵單擊JFrame中,並打開其屬性對話框。點擊屬性標籤。

在Properties選項卡下,找到並修改title字段。 NetBeans將完成剩下的工作。

0

好了,這個工作對我來說...

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 
} 

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

2

Setting title in JFrame Netbeans Swing

你可以看到在屬性窗口標題屬性(右下側)。點擊該屬性即可設置標題。 如果您無法找到屬性窗口,只需點擊設計選項卡,然後點擊空白的JFrame GUI。