【发布时间】:2016-04-05 15:57:55
【问题描述】:
当JDialog 调整为更小的尺寸时,它将从下到上切割。
但是如何使它成为底部将是“更高的优先级”,JDialog 将首先切割顶部并保持底部不切割。
调整大小之前:
调整大小后(顶部面板正常,但底部面板被剪切):
在这种情况下,我希望切割顶部面板并且底部面板正常
来源:
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class DlgTest extends JDialog {
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
DlgTest dialog = new DlgTest();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the dialog.
*/
public DlgTest() {
setBounds(100, 100, 450, 300);
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel top = new JPanel(new FlowLayout());
top.add(new JButton("t1"));
top.add(new JButton("t2"));
JPanel bottom = new JPanel(new FlowLayout());
bottom.add(new JButton("b1"));
bottom.add(new JButton("b2"));
mainPanel.add(top, BorderLayout.PAGE_START);
mainPanel.add(bottom, BorderLayout.PAGE_END);
add(mainPanel);
}
}
【问题讨论】:
标签: java swing layout-manager jdialog