Skip to content
Advertisement

Can’t Change button or panel location in Swing (Java)

I can’t change the location of Button or Panel in “setbounds” in java swing.It’s just stuck to the top. What should I change here? Should I add a “Gridlayout” to the button or something? Changing the panel location does nothing for the button.

public class Main {

JavaScript

enter image description here

Advertisement

Answer

In Java Swing, a layout manager decides on where the contained components are getting placed. The default layout of a JFrame is BorderLayout which places the components in regions around the border (or center).

If you want to place your components freely, you have to “disable” your layout.

JavaScript

This should work as intended.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement