netbeans: How to put some title in the title bar
I developed a small desktop ap开发者_Python百科plication in Net Beans. When i run my application there appears no title in the Windows Title bar. Is there anyway through which i specify some title which later on will appear in Windows title bar? Following is my Main method
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MyJFrame().setVisible(true);
}
});
}
You can see title property in properties window (Bottom right side). You can set title upon clicking that property. If you are unable to find property window, just click on Design tab and then on blank JFrame GUI.
You can set the title bar at JFrame initialization time like this
JFrame frame = new JFrame("My Title");
or you can create public method for your custom class like
public void setTitle(String title){
frame.setTitle(title); // for this you have declare the frame object as global for this class only
}
and use like this way
MyJFrame myframe = new MyJFrame();
myframe.setTitle("my new title");
myframe.setVisible(true);
myTopLevelContainer = new myTopLevelContainer("myTitlaLabel");
or
myTopLevelContainer.setTitle("myTitlaLabel");
From the NetBeans Wiki:
To give your application a title, right click on the JFrame and open its properties dialog box. Click the properties tab.
Under the Properties tab, find and modify the title
field. NetBeans will do the rest.
Okay, this worked for me ...
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
}
so what I did was put the above code in the generated public method.
精彩评论