This is my first time learning Java Swing and I had a label and setLocation wasn't working. Someone told me it's because you have to set the layout to null
, otherwise they're set to default locations and sizes. So I did, and now my label isn't appearing
import java.util.*;
import javax.swing.*;
public class School {
private ArrayList <String> Usernames = new ArrayList <> ();
private ArrayList <String> Passwords = new ArrayList <> ();
public void registerUser(){
JFrame Register = new JFrame("Register");
JLabel Username = new JLabel("Username: ");
Username.setBounds(50, 50, 100, 30);
Register.add(Username);
Register.setVisible(true);
Register.setSize(500, 500);
Register.setLayout(null);
Register.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main (String [] args){
School example = new School();
example.registerUser();
}
}