Pb with JTabbedPane

In my application, i've build a JTabbedPane, with 2 tabs.
The second tab contains a JPanel which contains a subclass of Canvas at the center.

When i start the application, the first tab is selected, but it paint the canvas of the second tab. Then, when i select de 2nd tab then the 1st by clicking, the content of the 1st tab become correct again.
It's at the init of the JTabbedPane that the problem occur.
I've tried to call :
tabbedPane.setSelectedIndex(1);
tabbedPane.setSelectedIndex(0);
to force to repaint 2nd tab then 1st tab, but to no effect.

Does anybody know this problem or similar ?
Thanks a lot.
stdtAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
objectsConnect With a Mentor Commented:
You should not be using a heavyweight component (Canvas) inside your JTabbedPane (lightweight component).
Instead of using a Canvas just use a JPanel, or subclass JComponent.
0
 
Venci75Commented:
try to call the repaint() method explicitly
0
 
stdtAuthor Commented:
I've tried to call the repaint() method and even the repaintImmediately(...) method, unsuccessfully.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
stdtAuthor Commented:
I've tried to call the repaint() method and even the repaintImmediately(...) method, unsuccessfully.
0
 
stdtAuthor Commented:
I've tried to call the repaint() method and even the repaintImmediately(...) method, unsuccessfully.
0
 
stdtAuthor Commented:
OTHER QUESTION :
I've made a test by replacing the Canvas by a JPanel in the 2nd tab, and the problem has disapeared. In fact the Canvas witch is AWT is painted wherever it is. And the management of a JTabbedPane with a Canvas is bad.
In fact, i use a Canvas component because i just need to paint in the Graphics.

Is there a Swing component like Canvas in AWT ?
0
 
objectsCommented:
Just use a subclass of JComponent, or a JPanel.

Thanks for the points :-)

http://www.objects.com.au
Brainbench MVP for Java 1
http://www.brainbench.com
0
All Courses

From novice to tech pro — start learning today.