问题描述
因此,我正在使用Eclipse WindowBuilder设计JFrame.此特定帧是一条错误消息,指出用户提供了无效的凭据.我添加了一个退出框架的按钮,现在我需要显示实际的错误消息指定的登录凭据无效.请提供有效的凭据."
So I am designing a JFrame using Eclipse WindowBuilder. This specific frame is an error message stating that the user provided invalid credentials. I have added a button to exit the frame and I now need to display the actual error message "The login credentials specified are invalid. Please provide valid credentials."
我已经进行了一些搜索,每个人都说要使用JLabel,但是当我创建JLabel并在其中输入文本时,没有自动换行或其他任何操作,因此我无法将标签放入框架中.
I have done some searching and everyone says to use a JLabel, but when I create my JLabel and enter the text to it, there is no wordwrap or anything so I can't fit the label inside my frame.
在JFrame的中心简单显示一条消息的简单方法是什么?
What is an easy way to simply display a message in the center of the JFrame?
推荐答案
为文本创建标签:
JLabel label1 = new JLabel("Test");
要更改标签中的文本,请执行以下操作:
To change the text in the label:
label1.setText("Label Text");
最后清除标签:
label1.setText("");
所有您需要做的就是将标签放置在布局中,或使用的布局系统中,然后将其添加到JFrame中.
And all you have to do is place the label in your layout, or whatever layout system you are using, and then just add it to the JFrame...
这篇关于如何在JFrame中添加文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!