java - JDialog 调整大小时不剪切底部面板

标签 java swing layout-manager jdialog

JDialog调整为较小尺寸时,它将从下到上剪切。 但如何使其如此底部将是“更高的优先级”,JDialog 将首先切割顶部并保留底部不切割。

调整大小之前:

enter image description here

调整大小后(顶部面板正常,但底部面板被剪切):

enter image description here

在这种情况下,我希望顶部面板被切割,底部面板正常

来源:

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);
    }

}

最佳答案

您可以使用 BorderLayoutCENTERSOUTH 约束:

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

南部部分不应被切割。

关于java - JDialog 调整大小时不剪切底部面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36431411/

相关文章:

Java - 无线 API

java - 如何使用 Google Dictionary 作为 API?

java - Jlabel 不会使用 ActionListener 中的 setText 进行更新?

java - 如何使用 GridBagLayout 制作单列按钮?

java - 将 double 转换为 long 时发生转换错误

java - 使用 JOOQ 插入忽略多个 pojo

java - 从另一个 Swing 类向 Swing 类返回一个值

java - 通过 JScrollPane 异常行为重新调度 MouseEvent

java - JOptionPane 在不同的行上有多个输入

java - 使用 JFrame/JPanel/Netbeans 自定义图形位置