如何在添加其他对象的同时将 MyDrawPanel 添加到程序中?

发布于 2024-10-08 22:47:23 字数 225 浏览 0 评论 0原文

我正在尝试制作一个简单的游戏,并且已成功将图像加载到 JFrame 上的 myDrawPanel 上。但是,我还想向 GUI 添加其他内容,例如按钮等。但是,我不能这样做,因为当我将 myDrawPanel 添加到 JPanel 时,我得到的只是窗口顶部中心的一个小方块。事实证明,这是一个很大的限制,我想知道是否有一个替代的“JObject”,我可以将 myDrawPanel 添加到其中,以便自定义我的 GUI。预先感谢,圣诞快乐!

I am attempting to make a simple game, and I have loaded an image onto a myDrawPanel, which is on the JFrame, successfully. However, I also want to add other things to my GUI, such as buttons, etc. I cannot do this, however, because when I add the myDrawPanel to a JPanel, all I get is a small square in the top center of the window. This is proving to be greatly limiting, and I was wondering if there is an alternative "JObject" that I can add the myDrawPanel to in order to allow for the customization of my GUI. Thanks in advance, and Merry Christmas!

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

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

发布评论

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

评论(2

乱世争霸 2024-10-15 22:47:23

JPanel(或子类)通常从它包含的组件中获取其大小。如果里面没有任何组件,它就会很小。

解决此问题的一种方法是在自定义面板上调用 setPreferredSize(Dimension)。

A JPanel (or sub-class) generally obtains its size from the components it contains. If no components are in it, it will be small.

One way to fix that is to call setPreferredSize(Dimension) on the customized panel.

灰色世界里的红玫瑰 2024-10-15 22:47:23

p1.setPreferredSize(new Dimention(1100,800));

p1.setPreferredSize(new Dimention(1100,800));

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