Ignore the recommendation to call pack()
on the class above as it does not work for JPanels. Instead, don't set your JPanel's size or preferred size -- let the components themselves and your layout managers do that. Then add all items to the JFrame, call pack()
on it after adding all items, and then call setVisible(true)
on it, in that order.
Oh, you will want to change your startbutton class name to StartButton since Java class names should begin with an upper case letter, and you should use camel-case names for all identifiers except constants.
If you're still stuck after trying out these recommendations, then consider creating and posting your minimal code example program for us to review, test, and possibly fix.