JDialog allow user to only change width of the dialog

时间秒杀一切 提交于 2019-12-01 08:31:34

You could add a ComponentListener to the JDialog, and check in componentResized if height changed. This could be implemented by extending the JDialog class this way:

public class Dialog extends javax.swing.JDialog {

    public Dialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        final int h = getHeight();
        addComponentListener(new ComponentAdapter() {

            @Override
            public void componentResized(ComponentEvent e) {
                Rectangle b = getBounds();
                if (b.height != h) {
                    b.height = h;
                    setBounds(b);
                }
                super.componentResized(e);
            }
        });
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!