I have a JFrame that displays JPanels depending on the MenuItem you click. It works, but now I need to call a method once a JPanel is added to the frame and it is being show
The JPanel is not visible until Thread.sleep finishes. Why? What am I doing wrong?
don't block Event Dispatch Thread, Thread.sleep(int) block EDT, Swing GUI waiting untill this delay ended, and all change made during Thread.sleep(int) would not be visible on the screen, use Swing Timer instead, otherwise all changes to the Swing GUI must be wrapped into invokeLater()
Swing is single threaded and all updates to the visible GUI (or stated out of invokeLater) must be done on EDT, more in Concurency in Swing
for better help sooner post an SSCCE, short, runnable, compilable