I tried using .setVisibility(true) but got a NullPointerException. How can I do this more effectively? I want the labels and fields to start invisible then become visible when the user presses a button. I also want to change the size of an object. Ideas?
Heres one of the line of error:
public JLabel lblName;
JLabel lblName = new JLabel("Name:");
lblName.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblName.setBounds(10, 91, 79, 19);
panel.add(lblName);
lblName.setVisible(false);
public void actionPerformed(ActionEvent e) {
lblName.setVisible(true);
}
All of the above are seperate code snippets that worked flawlessly until I added the 3rd snippet.
Judging from the code in your question:
You have a field and local
JLabel lblNameYou are not initializing the field, only the local variable. Hence your exception.