• Post Reply Bookmark Topic Watch Topic
  • New Topic

inserting canvas in a panel

 
srinivas bolloju
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have tried this in numerous ways but couldnt succed,still trying, here is the problem.
I have a JFrame which i have divided into so many cells using gridbaglayout, in one big cell, i placed a jpanel, it has hscroll and vscroll bars, i have to insert canvas into this panel. here is where im failing. i have used a seperate class for canvas which im instantiating and adding to this panel, not working., i have used a innerclass where im calling method which does the painting, this is also not working, it doesnt give any error. but nothing appears in my canvas... could somebody give some solution.
thanks in advance
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure that you are setting a preferred size on your "canvas" object...

(And it would really help if you posted the code... )
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry to play the dunce, but how does one do that? i see no method setPreferredSize in the Canvas specs, and i know that I have setBounds on my canvas, which includes setting th size, and i still experience this problem
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're actually using java.awt.Canvas, then the problem is that you're mixing Swing and AWT components. You should use a JPanel instead, and override "paintComponent( Graphics g )" instead of "paint( Graphics g )".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!