I'm trying to make a basic UI with Swing. I want to have a JFrame with a JTabbedPane with multiple Tabs. If I only make 1 JPanel with a JTextField it works fine, but as soon as I want to add another JPanel with a JTextField it just shows nothing. What am I doing wrong here?
Here is a quick example:
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
public class SwingUI {
private final JFrame frame;
private final JTabbedPane tabbedPane;
public SwingUI(){
frame = new JFrame("Test");
frame.setSize(1000, 1000);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new GridLayout(1, 1));
tabbedPane = new JTabbedPane();
tabbedPane.addTab("Login", makeLoginPanel());
tabbedPane.addTab("Login2", makeLoginPanel()); //if this is left out it works
frame.getContentPane().add(tabbedPane);
}
private JPanel makeLoginPanel(){
JPanel p = new JPanel();
p.setLayout(null);
JLabel lblName = new JLabel("Name:");
lblName.setBounds(50,50,100,30);
p.add(lblName);
JTextField x = new JTextField("text");
x.setBounds(200,200,200,200);
p.add(x);
return p;
}
}