Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Canvas in JScrollPane

 
Rajesh Kumarv
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
how do i add a Canvas into a JScrollPane ???
i tried it but the canvas appears over the JScrollPane
try it and help me
bye
rajesh
 
darren green
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello, i believe you want to use the JPanel class instead of the canvas class. i had the same problem and that fixed it up straight away.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is happening because you are mixing AWT (heavy-weight) components and Swing (light-weight) components... The Canvas is still AWT, while the JScrollPane is Swing... follow Darren's suggestion above, it should fix your problem...

-Nate
 
Amit Rosner
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the same problem still.
I have a panel, whose layout is GridLayout, that contains Canvas Objects, each in its own new JPanel. All of the canvas objects are lined in one column, using the GridLayout. New canvas objects can be added dynamically to the panel, at the bottom.
Now, this panel is contained in a JScrollPane. As long as there is no need for the scrollbars to appear, i.e. all of the canvas object can be shown together, there is no problem.
But, when scroll is needed, the region of the canvas that need not to be shown until scrolled to it is still visible.
I mean: the scroll works ok, I can scroll both horizontally and vertically, but all of the canvas objects that need to be hidden at the bottom (and their rightmost regions) are visible, overriding other components below the scrollpane, and the scrollpane's vertical scrollbar.
How can I fix it, so that whenever I scroll, all of the unnecessary drawing will be hidden until scrolled to?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, No, No! You cannot use Canvas anywhere at all in your program because it is an AWT component and will always float to the top in Swing. You have to replace your Canvas component with an extended JPanel or JComponent that does the same thing as your Canvas.

-Nate
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic