I am using the following code to create a very simple JFrame
, but for some reason it doesn\'t show any components, just a blank frame. Why is this happening? I
Better your first add components to your variable "panel" and add then your finished panel to the .getContentPane().add()
.
And the most important issue is that you better call frame.setVisible(true);
at the end of your method.
Put frame.setVisible(true);
after adding components to JFrame
, and it will show all the added components. Moreover, you should use specific layout rather than setting bounds for components. You can use a Layout Manager.
You have to move frame.setVisible(true);
to the end of the method; the visibility must be set to true after you have added the components.
Alternatively, you can add the following to the end of your method:
frame.revalidate();
frame.repaint();
to revalidate and repaint the frame with the newly added components although I recommend the former method.
you can add this at the end;
frame.pack()