JDialog allow user to only change width of the dialog

后端 未结 1 692
无人及你
无人及你 2021-01-21 04:01

Does anyone know if it is possible to limit how the user resizes a JDialog?

I know i can call the method setResizible(boolean) and that disables or enables the user from

相关标签:
1条回答
  • 2021-01-21 05:04

    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);
                }
            });
        }
    }
    
    0 讨论(0)
提交回复
热议问题