Why are my items not showing up in JFrame?

but when i run it i get this:

You get an empty screen because you add the components to the frame after the frame is visible.

  1. As has already been suggested you need to use an appropriate layout manager. FlowLayout is the easiest to start with.
  2. invoke setVisible(true) AFTER adding the components to the frame.

So the code should be more like:

panel.add(...);
panel.add(...);
add(panel);
pack();
setVisible(true);

Leave a Comment