How to layout? (JFrame, JPanel, etc.)(如何布局?(JFrame、JPanel 等))
问题描述
我对 Java Swing 和 Java 整体来说非常新手(我的课程刚刚完成了 Scanner
和基础知识).我只学习了 Swing 基础知识,即什么是 JFrame..etc",但我一直坚持如何布局或定位事物.图片上是我想要的布局,谁能帮助并教我如何编码?JFrame
有,5 个 JPanel
组件?(4 列和下面的订单)
I'm very new to Java Swing and Java overall (my class just got finished on Scanner
and basics). I was taught only Swing basics which is "What is a JFrame..etc" and I'm stuck on how to layout or position things. On the image is the layout I desired and could anyone help and teach me how to code it? JFrame
with, 5 JPanel
components?(4 columns and the order form below)
此外,当单击确认"按钮时,我希望弹出一个新窗口.如何链接多个窗口?
Additionally, when clicking the "CONFIRM" button, I would want a new window to popup. How would I be able to link multiple windows?
推荐答案
解决复杂计算任务的常用策略是将它们分解成小的、定义明确的可管理任务.分而治之.
这也适用于 gui:将设计分解为易于布局的小容器.例如:
A common strategy to solve complex computing tasks, is to break them into small, well defined manageable tasks. Divide and conquer.
This also applies to gui: break the design into small, easy to layout containers. For example:
您可以看到四个相当简单且不同的容器,分别名为 headerPane
、listPane
、inputPane
和 buttonsPane
.mainPane
只是扭曲(包含)这四个.inputPane
区域被分成多个容器,以保持布局简单.
You can see four fairly simple and distinct containers, named headerPane
, listPane
, inputPane
and buttonsPane
.
The mainPane
just warps (contains) those four.
The inputPane
area is divided into containers, to keep the layout simple.
这个想法是保持每个容器布局简单,易于遵循和更改.headerPane
可以这么简单:
The idea is to keep each container layout simple, easy to follow and change.
headerPane
can be as simple as:
JPanel headerPane = new JPanel(); //uses flow layout by default
JLabel header = new JLabel("LUNA BOOKSTORE ORDER FORM", JLabel.CENTER);
headerPane.add(header);
buttonsPane
可以这么简单:
JPanel buttonsPane = new JPanel(); //uses flow layout by default
buttonsPane.add(new JButton("CONFIRM"));
buttonsPane.add(new JButton("RESET"));
buttonsPane.add(new JButton("EXIT"));
<小时>
应用此策略的更多示例:1 2 和 3
这篇关于如何布局?(JFrame、JPanel 等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何布局?(JFrame、JPanel 等)
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 转换 ldap 日期 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 获取数字的最后一位 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01