布置 JPanel 来制作简单的 GUI

发布于 2024-09-04 01:35:07 字数 642 浏览 2 评论 0原文

首先,这或多或少是我的第一个 GUI,而且我学习 Java 的时间不超过一周,因此它可能包含一些严重的编程错误。

我现在拥有的是: 按钮和标签是 OptionPanel 的一部分,位于左侧,DrawingPanel 大小约为 5x5 像素,位于右侧。

我想做的是一个简单的测试,让我更熟悉 GUI。当用户单击相应的按钮时,矩形应该是可移动的并可调整大小: http://www.upload.ee/image/612005/JFrame2.jpg

现在我有:

JFrame MainFrame - 制作 JFrame (不使用 setSize 函数。使用 .pack() 代替。不确定)

JPanel MergedPanel - FlowLayout - 将 JPanel OptionsPanel 和 JPanel DrawingPanel 添加到一起并注入到 JFrame MainFrame

JPanel DrawPanel - 这个 JPanel 负责绘制矩形。 JPanel OptionPanel - FlowLayout - 此 JPanel 负责按钮。

请帮忙。

first of all, this is more or less my first GUI and ive learned Java for not more then a week, so it might contain some serious programming errors.

What i have right now is:
Buttons and labels are part of OptionPanel and are on the left, DrawingPanel is about 5x5 px in size and is on the right.

What I am trying to do is a simple test, to get me more familiar with the GUI. The rectangle should be movable and re-sizeable by the user when clicking the respective buttons:
http://www.upload.ee/image/612005/JFrame2.jpg

Right now i have:

JFrame MainFrame - Makes JFrame (Not using the setSize function. using .pack() instead. not sure about it)

JPanel MergedPanel - FlowLayout - Adds JPanel OptionsPanel and JPanel DrawingPanel together and gets injected to JFrame MainFrame

JPanel DrawPanel - This JPanel is responsible of drawing the rectangle.
JPanel OptionPanel - FlowLayout - This JPanel is responsible of the buttons.

Help please.

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

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

发布评论

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

评论(2

划一舟意中人 2024-09-11 01:35:07

您永远不应该在代码中调用 setSize()。在 Java 中,您可以使用 布局管理器 来执行以下操作:布局(阅读该教程)。

子类化 JPanel 来实现组成 UI 的不同部分是一种很好的做法,但不应该过度(有一个 UI 类添加 3 个其他普通 JPanel 就可以了)用于布局目的的实例)。

You should never call setSize() in your code. In Java, you use layout managers to do the layout (read that tutorial).

Subclassing JPanel to implement different parts of which the UI is composed is a good practice, but should not be overdone (it's fine to have an UI class that adds 3 other plain JPanel instances to itself for layout purposes).

过去的过去 2024-09-11 01:35:07

查看 MiG Layout :可以用它轻松制作 java 布局。

Check out MiG Layout : one can make pretty easily java layouts with that.

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