How to dynamically control auto-resize components in Java Swing

后端 未结 5 1842
耶瑟儿~
耶瑟儿~ 2020-12-15 22:25

Creating a new GUI in Java (1.8) Swing, I am searching for a way to override resize behavior of all my components.

Let me explain to you with some edited photos:

5条回答
  •  醉话见心
    2020-12-15 23:10

    This is how I do it and I am not sure this is the proper way:

    First set the layout to null.

    Next create a component resized event for your frame:

    addComponentListener(new ComponentAdapter(){
                public void componentResized(ComponentEvent e){
                }
            });
    

    Inside here you can manually make changes to the components as it is resized. I have done this for a few of my programs to keep a scroll pane on the left and right of the frame always the same width and have everything else size up and down as resized.

提交回复
热议问题