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

查看:105
本文介绍了如何布置? (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秒登录
发送“验证码”获取 | 15天全站免登陆