如果 BorderLayout 约束为 CENTER,JScrollPane 不显示?

发布于 2024-08-16 18:49:46 字数 672 浏览 7 评论 0原文

开发游戏已经有一段时间了,目前正在重新设计 GUI,或者至少正在尝试这样做。存在无法调整框架大小(没有问题)的大问题,因为我不太了解布局管理器。几个项目之后,是时候回来对游戏做更多的事情了,我遇到了一个问题...

主框架的基本布局是 mainPane,包含一个 gameScrollPane 和一个 controlPanel。滚动窗格是滚动窗格,控制面板是普通面板。滚动窗格包含主游戏面板。

由于我希望滚动窗格占据大部分屏幕,而控制面板占据较小的下部区域,与许多模拟游戏类似,因此为 mainPane 选择了边框布局。我添加了滚动窗格并设置了 CENTER 约束,并添加了控制面板和 SOUTH 约束。这没有显示滚动窗格,所以我尝试了不同的约束,似乎只有当我将滚动窗格约束设置为北时,它才会显示。

为了证明这一点,我创建了一个快速视频...... http://screenjel.ly/q5RjczwZjH8

如您所见,当我将 NORTH 的值更改为 CENTER 并重新运行,就像不存在一样!

对于任何能够看到清晰的第二个问题的人来说,奖励积分,在这个问题解决后我可能会开始另一个问题!

我感谢您花时间阅读本文。

预先感谢您的任何想法或想法:)

Rel

Been developing a game for a while, and currently re working the GUI, or at least trying to. Had the massive problem of not being able to resize the frame (without issues), as I didn't understand layout managers very well. A few projects later, and time to come back and do some more on the game, and I hit a problem...

The basic layout of the main frame is, mainPane, containing one gameScrollPane and one controlPanel. The scroll pane is a scroll pane, and the control panel a normal panel. The scroll pane contains the main game panel.

As I wanted the scroll pane to take up most of the screen, with the control panel taking up a small lower area, much the same as many Sim like games, so chose the Border layout for the mainPane. I added the scroll pane and set the constraints CENTER and the control panel added and constriants SOUTH. This didn't show the scroll pane, so I played around trying different constraints, and it seems that only when I set the scroll pane constraint to North, does it display at all.

To demonstrate this, I have created a quick video...
http://screenjel.ly/q5RjczwZjH8

As you can see, when I change the value of NORTH to CENTER and re run, it's like its not there!

Bonus points for anyone who can see a clear second problem which I may start another question for after this issue is solved!

I thank you for your time to read this.

Thanks in advance for any ideas or thoughts :)

Rel

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

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

发布评论

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

评论(2

江湖正好 2024-08-23 18:49:46

如果您首先发布了一些代码,那么您可能会得到一个非常快速的答案。幸运的是,您在评论中发布了其他回复的链接。

setContentPane() 的东西很奇怪,特别是在对它做了一些事情之后,这些东西就会被清除。然而,这不是你的问题。

问题是您将 levelMaker 和 personMover 添加到 mainPane 中,没有任何限制。然后,这些将吹走您为 CENTER 设置的任何内容...在本例中为先前设置的 gameScrollPane。

这就是为什么您看到的是“北”而不是“中心”。

If you'd posted some code to start with then you might have gotten a really quick answer. Luckily, you posted a link in the comments to the other response.

The setContentPane() stuff is weird, especially after doing some things to it that will then get wiped out. However, that's not your problem.

The issue is that you are adding levelMaker and personMover right to mainPane without any constraints. These will then be blowing away anything you set for CENTER... in this case the previously set gameScrollPane.

That's why you see it for NORTH and not for CENTER.

心不设防 2024-08-23 18:49:46

我无法显示视频。已经缓冲了很多年了。

我的猜测是滚动窗格实际上填充了中心;只是您的游戏面板没有显示。

您的游戏面板需要为 getPreferredSize() 返回合理的值。

更新

您可能想要做的另一件事是让您的游戏面板实现Scrollable 界面。然后,您可以覆盖 getScrollableTracksViewportWidth...height 以返回 true,这样您的面板将被强制为滚动窗格的尺寸。

I can't get the video to show. It's been buffering for ages.

My guess would be that the scrollpane is in fact filling the center; it's just your game panel that's not being shown.

Your game panel needs to return reasonable values for getPreferredSize().

Update

Another thing you may want to do is have your game panel implement the Scrollable interface. You can then override getScrollableTracksViewportWidth and ...height to return true so your panel will be forced to the scrollpane's dimensions.

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