Swing components repaint when added after init
Posted on 1998-06-17
I have encountered a problem with the repaint method of Swing components.
I'm trying to add a JPanel subclass, with lots of swing components on it, to a JApplet.
When the JPanel is created and added to the applet in its init method, the JPanel is painted as it should.
But, when I tried to create the same JPanel subclass using a second thread and add it to the JApplet (after the JApplet was initiated and started) most components were not painted.
Minimizing the window and maximizing it back refreshs the JPanel subclass but some components (JSplitPane for example) are seen only in the upper left corner of their position in the screen (2 pixels * 2 pixels) and are repainted properly only after you click these tiny (2 pixels * 2 pixels) components.
I solved the first problem of the components that were not painted at all by creating & adding the JPanel subclass in an invisible state and was setting it back to visible afterwords and most of the components appeared just fine.
Still, the problem that bothers me is the fact that the JSplitPane for example is painted in a tiny size of (2 pixels * 2 pixels).
I would most appriciate it if anyone knows how I may tell the JSplitPane to be repainted properly (as happens when it is clicked). I already tried calling repaint, invalidate ... etc, but nothing helped.
Thanks in advance,