如何布局?(JFrame、JPanel 等) [英] How to layout? (JFrame, JPanel, etc.)

查看:55
本文介绍了如何布局?(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:

您可以看到四个相当简单且不同的容器,分别名为 headerPanelistPaneinputPanebuttonsPane.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 23

这篇关于如何布局?(JFrame、JPanel 等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆