Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

canvas on JTabbedPane

 
Sarone Thach
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I have this problem I have been battling with for over a week now.
I have a JTabbedPane and added a JPanel to index 0, behind (index 1) it i added a JPanel with a custom Canvas and other components, ie myCanvas extends Canvas.
The problem is, when run my program, the canvas is painted on top of the JTabbedPane, when its supposed to be hidden with all the "other components". If I select index 1 of the JTabbedPane everything in this page is displayed. if i select index 0, it shoulds everything in index 0, without the canvas. So only on initial start up i have this problem.
So i figured my canvas class is wrong. But don't know actually what is wrong.
I would submitt the code, but it's very long.
Does anyone have a clue why the canvas insists being on top when its not supposed to be on startup?
thanks,
Sarone
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Canvas is an AWT component... JTabbedPane and JPanel are Swing Components...

You shouldn't mix the two.

Replace your subclass of Canvas with a subclass of JPanel (and put the code from the Canvas's paint() method into the JPanel's paintComponent() method) and it should work, though.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic