手动将 JComponent 放置在 JPanel 内

发布于 2024-09-01 11:29:24 字数 95 浏览 2 评论 0原文

我想以编程方式将 JLabel 移动到 JPanel 内的特定位置。我尝试过 setLocation(int x, int y) ,但它不起作用。 我试图不使用任何布局管理器。

I want to programmatically move my JLabel to a specific location inside my JPanel. I have tried setLocation(int x, int y), but it doesn't work.
I am trying to not use any layout manager.

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

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

发布评论

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

评论(1

盗心人 2024-09-08 11:29:24

这是一个关于如何在不使用布局管理器的情况下布局组件的精彩教程。

http://java.sun.com/docs/books/tutorial /uiswing/layout/none.html

创建没有布局管理器的容器涉及以下步骤。

  1. 通过调用 setLayout(null) 将容器的布局管理器设置为 null。
  2. 为每个容器的子级调用 Component 类的 setbounds 方法。
  3. 调用 Component 类的 repaint 方法。

Here is a great tutorial on how to layout your components without using a layout manager.

http://java.sun.com/docs/books/tutorial/uiswing/layout/none.html

Creating a container without a layout manager involves the following steps.

  1. Set the container's layout manager to null by calling setLayout(null).
  2. Call the Component class's setbounds method for each of the container's children.
  3. Call the Component class's repaint method.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文