Java GUI 101 - changing the title of a JPanel
Solution 1
First of all, the link you provided contains a JFrame
not JPanel
.
Second, pass the title as a parameter to the JFrame
constructor once you create it JFrame(String title)
:
JFrame myFrame = new JFrame("My Title");
or use the method setTitle(String title)
inherited from class Frame
:
myFrame.setTitle("My Title");
Solution 2
The element in the screen you linked to looks like a JFrame
, and not a JPanel
. The setTitle()
method should do the trick.
Solution 3
It's not the JPanel
, I think it will be the JFrame
that you want to change, it has a setTitle()
method you can use.
Also the constructor for the JFrame
takes a string argument for it's title
Solution 4
Or if you don't have access to the JFrame directly (or just want to do it in a neater, more portable fashion)
SwingUtilities.getRoot(this).setTitle("SomeTitle);
Solution 5
That's not a JPanel. It's a JFrame
that contains JPanel
s.
The title can be set in the constructor, and can be changed with setTitle()
If you read the tutorial you're linking to, you'll note that there's a link to the "Converter" application. Further reading would take you to the source for that tutorial application:
//Create and set up the window.
JFrame frame = new JFrame("Converter");
foaf
Updated on July 02, 2020Comments
-
foaf almost 4 years
Simple question here. How do I change the title of a
JPanel
, for exmplehttp://docs.oracle.com/javase/tutorial/figures/uiswing/components/ConverterColored.png
change the text "converter" here to something else?
Thanks in advance!
EDIT: sorry, it was a
JPanel
! -
trashgod over 12 yearsSee also the whole Converter Project.