Setting minimum size limit for a window in java swing

前端 未结 2 1705
猫巷女王i
猫巷女王i 2020-12-06 04:18

I have a JFrame which has 3 JPanels in GridBagLayout..

Now, when I minimize a windows, after a certain limit, the

2条回答
  •  醉酒成梦
    2020-12-06 04:38

    There actually is a way to ensure minimum size on any platform. You need to set the minimum size of the JFrame to the minimum size of its content pane and then you need to write a ComponentAdapter and override componentResized. Then you just use getSize and getMinimum size on your JFrame and substitute width and/or height with the minimum width or height if it is greater. Assuming you are extending JFrame:

    this.addComponentListener(new ComponentAdapter(){
            public void componentResized(ComponentEvent e){
                Dimension d=YourJFrame.this.getSize();
                Dimension minD=YourJFrame.this.getMinimumSize();
                if(d.width

提交回复
热议问题