这里的简单问题。如何更改JPanel
的标题,例如
http://docs.oracle.com/javase/tutorial/figures/uiswing/components/ConverterColored.png
将文本“转换器”更改为其他内容?
提前致谢!
编辑:抱歉,这是JPanel
!
答案 0 :(得分:10)
其次,在创建JFrame
后,将标题作为参数传递给JFrame(String title)
构造函数:
JFrame myFrame = new JFrame("My Title");
或使用继承自班级setTitle(String title)
的方法Frame
:
myFrame.setTitle("My Title");
答案 1 :(得分:6)
您关联的屏幕中的元素看起来像JFrame
,而不是JPanel
。 setTitle()
方法应该可以解决问题。
答案 2 :(得分:5)
这不是JPanel
,我认为您想要更改JFrame
,它可以使用setTitle()
方法。
此外,JFrame
的构造函数为其标题
答案 3 :(得分:3)
或者,如果您无法直接访问JFrame(或者只是想以更整洁,更便携的方式进行)
SwingUtilities.getRoot(this).setTitle("SomeTitle);
答案 4 :(得分:2)
那是不是 JPanel。它是JFrame
,包含JPanel
s。
标题可以在构造函数中设置,可以使用setTitle()
如果你阅读了你要链接的教程,你会注意到有一个指向“转换器”应用程序的链接。进一步阅读将带您到该教程应用程序的源代码:
//Create and set up the window.
JFrame frame = new JFrame("Converter");
答案 5 :(得分:1)
这将是一个TitledBorder。 请参阅:http://docs.oracle.com/javase/tutorial/uiswing/components/border.html