set size wont work in java

后端 未结 3 593
闹比i
闹比i 2021-01-05 04:38
public void start_Gui() {

    JFrame window = new JFrame(\"Client Program\");
    window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JP         


        
相关标签:
3条回答
  • 2021-01-05 05:03

    In Swing, you have two options for layout: do everything manually or let a LayoutManager handle it for you.

    Calling setSize() will only work when you're not using a LayoutManager. Since you're using a GridLayout you'll have to use other ways to specify what you want.

    Try calling setPreferredSize() and setMinimumSize().

    0 讨论(0)
  • 2021-01-05 05:09

    but setXxxSize (for ContainersChilds) works as chaims if you change from setSize() (for TopLayoutContainer) to setPreferredSize() and you have to call pack() before setVisible()

    0 讨论(0)
  • 2021-01-05 05:22

    Two things - firstly you should be setting the preferredSize of the scrollpane, but secondly, trying to resize it inside the componentResized handler isn't a very effective technique because the 'resized' events aren't continuous.

    check resizing text area in a JFrame

    0 讨论(0)
提交回复
热议问题