Starting GridBagLayout from top left corner in Java Swing

后端 未结 6 641
执念已碎
执念已碎 2021-02-13 18:39

I\'m new to Java Swing and I have been struggling to start the GridBagLayout from top left corner so that c.gridx=0 c.gridy=0 will put my object on the top left corner.

6条回答
  •  走了就别回头了
    2021-02-13 19:02

    a quick and simple way:

    add a blank JLabel to end of page:

        // your code goes here
        gbc.weightx = 1;
        gbc.weighty = 1;
    
        bg.add(new JLabel(" "), gbc);  // blank JLabel
    

提交回复
热议问题