使用GetWidth();?

发布于 2025-02-09 13:15:34 字数 118 浏览 1 评论 0 原文

使用 getWidth()之后,如何显示面板的宽度?我可以将其放入 jtextfield / jtextarea 吗?我不这么认为,但我不确定。

How would I display the width of a panel after using getWidth()? Can I put it in a JTextField/JTextArea? I don't think so, but I'm not sure.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

八巷 2025-02-16 13:15:34

当然可以在文本组件中显示面板大小。您可以使用 setText(String t)方法来设置 jtextfield jtextarea 。尝试以下操作:

String width = myPanel.getWidth();
myTextField.setText(width);

它将在JTEXTFIELD中向用户显示面板的宽度。 (或者您可以将文本字段替换为您喜欢的任何文本组件)

您还可以查看 java教程 如何使用顶级容器 Java教程是Swing Developers的出色官方文件。

It is certainly possible to display the panel size in a text component. You can use setText(String t) method to set the display text of a JTextField or a JTextArea. Try this:

String width = myPanel.getWidth();
myTextField.setText(width);

It will display the width of the panel to the user in a JTextField. (Or you can replace the text field to any text components you like)

You can also take a look at these two sections in the Java Tutorial: How to use Top-Level containers and Using Text Components. The Java Tutorial is a great official document for Swing developers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文