【问题标题】:Don't cut bottom panel when JDialog resizesJDialog 调整大小时不要剪切底部面板
【发布时间】: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


    【解决方案1】:

    您可以使用BorderLayoutCENTERSOUTH 约束:

    mainPanel.add(top, BorderLayout.CENTER);
    mainPanel.add(bottom, BorderLayout.SOUTH);
    

    南部不应该被切割。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-20
      • 1970-01-01
      • 2011-02-05
      • 2013-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多