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 等)
基础教程推荐
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01