Absolute positioning Swing(Java) not working

163 Views Asked by At

I am trying to position something using absolute positioning, and for some reason when I run my code the window that previously worked, shows nothing.

This is the code that I have which works:

public LoginScreen() {
        window = new JFrame();
        login = new JPanel();

        username = new JTextField();

        login.add(username);
        window.add(login);

This is the code which does not work:

public LoginScreen() {
        window = new JFrame();

        login = new JPanel();
        login.setLayout(null);

        username = new JTextField();
        username.setBounds(50, 50, 100, 50);

        login.add(username);
        window.add(login);

I am not sure why the latter code is not working, someone please help!!

0

There are 0 best solutions below