【发布时间】:2016-05-18 15:01:08
【问题描述】:
如何在 Java 中获得这样的布局?
|---------------------------------------------- -|
|带标签的固定尺寸“顶部”面板
|----------------------------------------------|
|可调整大小的文本区域
|它扩展到大多数父级
|面板(固定区域除外)
|
|----------------------------------------------|
|固定 JTextArea(总是 2 行
|全画幅)
|----------------------------------------------|
|右居中按钮
|----------------------------------------------|
我尝试了下面的代码,但我无法让它工作。元素是浮动的,文本区域是冲突的。我不知道如何将文本区域扩展到所有可用的框架,除了固定区域。
JPanel top = new JPanel(new FlowLayout(FlowLayout.LEFT , 10, 10));
top.add(label1);
....
top.add(labelLast);
add(top);
JTextArea area1 = new JTextArea();
add(area1);
JTextArea area2 = new JTextArea();
add(area2);
JPanel bottom= new JPanel(new FlowLayout(FlowLayout.RIGHT , 10, 10));
bottom.add(button1);
....
bottom.add(buttonLast);
add(bottom);
【问题讨论】:
标签: java swing jpanel layout-manager