Java GUI 101 - JPanel name change

A simple question here. How to change JPanel header for exmple

http://docs.oracle.com/javase/tutorial/figures/uiswing/components/ConverterColored.png

change the text "converter" to something else?

Thanks in advance!


EDIT: Sorry, that was JPanel !

+4
source share
6 answers

First of all, the link you provided contains a non- JPanel JFrame .

Secondly, pass the title as a parameter to the JFrame constructor after you create it JFrame(String title) :

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

or use the setTitle(String title) method inherited from the Frame class:

 myFrame.setTitle("My Title"); 
+10
source

The item on the screen you are associated with looks like a JFrame , not a JPanel . The setTitle() method should do the trick.

+6
source

This is not a JPanel , I think it will be the JFrame that you want to change, it has a setTitle() method that you can use.
Also the constructor for JFrame accepts a string argument for the title

+5
source

Or if you don’t have direct access to the JFrame (or just want to do it more accurately, more portable)

 SwingUtilities.getRoot(this).setTitle("SomeTitle); 
+3
source

This is not a JPanel. This is a JFrame containing JPanel s.

The header can be set in the constructor and can be changed using setTitle()

If you read the tutorial to which you are attached, you will notice that there is a link to the Converter application. Further reading will lead you to the source for this tutorial application:

Converter application source

  //Create and set up the window. JFrame frame = new JFrame("Converter"); 
+2
source

Source: https://habr.com/ru/post/1384620/


All Articles