要使面板与空布局管理器一起工作,您必须做哪些事情?

发布于 2024-09-15 20:32:58 字数 261 浏览 8 评论 0原文

我在让空布局管理器工作时遇到问题,我发现这个很棒的页面包含使用空布局管理器时需要记住的事情。其中之一是我的问题,我很快就继续前进。

我现在使用空布局管理器的另一个面板也遇到类似的问题。但是,我在任何地方都找不到此页面!那么到底有哪些东西呢?

在问这个问题的过程中,我发现了自己的问题。我仍然想将这些知识添加到该网站,因为我在任何地方都找不到这个问题。这可能对其他人有帮助。

为了澄清,由于拖动和动画要求,我已经确定需要为此面板使用空布局管理器。这不是问题所在。

I was having problems getting a null layout manager working, and I found this great page with things to remember when using a null layout manager. One of them was my issue, and I quickly moved on.

I'm now having similar problems with another panel using a null layout manager. However, I cannot find this page anywhere! So what are the things?

In the process of asking this question, I figured out my problem. I still want to add this knowledge to the site, since I couldn't find this question anywhere. It might be helpful to someone else.

To clarify, I already have determined that I need to use a null layout manager for this panel, due to dragging and animation requirements. That is not the question.

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

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

发布评论

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

评论(2

倾城月光淡如水﹏ 2024-09-22 20:32:58

我找到了我正在寻找的链接:

http://download.oracle .com/javase/tutorial/uiswing/layout/none.html

它提供了以下三件事:

  • 通过调用 Container.setLayout(null) 将容器的布局管理器设置为 null。
  • 为每个容器的子级调用 Component.setBounds() 。
  • 调用 Component.repaint()

但碰巧的是,我的问题是我没有做一件额外的事情:

  • 使用 Container.add(Component) 将每个组件添加到容器中代码>

I found the link I was looking for:

http://download.oracle.com/javase/tutorial/uiswing/layout/none.html

It gives these three things:

  • Set the container's layout manager to null by calling Container.setLayout(null).
  • Call Component.setBounds() for each of the container's children.
  • Call Component.repaint()

As it happens, though, my problem was that I wasn't doing one additional thing:

  • Add each component to the container using Container.add(Component)
屌丝范 2024-09-22 20:32:58

无论您使用空布局还是 LayoutManager,都需要将组件添加到容器中。

我相信使用空布局时您需要记住的三件事是:

  1. 设置组件的大小(通常是首选大小)

  2. 设置组件的位置

  3. 设置包含组件的容器的首选大小。大多数情况下,如果您不设置首选大小,您的代码将起作用,但尝试将面板添加到滚动窗格时,它将不起作用。原因是当容器的首选大小大于滚动窗格的大小时,滚动条会自动出现。对于空布局,首选大小为 0。

Adding a Component to a Container is something you do whether you use a null layout or a LayoutManager.

The 3 things that I believe you need to remember when using a null layout are:

  1. set the size of the component (usually the preferred size)

  2. set the location of the component

  3. set the preferred size of the Container containing the components. Most time your code will work if you don't set the preferred size, but try adding the panel to a scroll pane and it won't work. The reason for this is that scrollbars appear automatically when the preferred size of the Container is greater than the size of the scrollpane. With a null layout the preferred size is 0.

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