File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jpane with scrollpane is not displaying

 
shalini gnana
Ranch Hand
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to add jpanel with the scrollpane,but my scrollpane is not displaying...

 
Brian Cole
Author
Ranch Hand
Posts: 886
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by shalini gnana:
I tried to add jpanel with the scrollpane,but my scrollpane is not displaying...


I see a couple of problems.

1) Don't use the add() method to put your JPanel in your JScrollPane. Either use the setViewportView() method or pass the JPanel in to the JScrollPane constructor.

2) Even if you add the JPanel to the JScrollPane correctly, you haven't added the JScrollPane to anything.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, don't forget to call super.paint(g) inside you're applet's paint method. Otherwise it won't refresh properly.
 
shalini gnana
Ranch Hand
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even now my scrollpane is not showing
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to set the layout of the panel to border layout.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maneesh Godbole:
You need to set the layout of the panel to border layout.

No you don't. The panel can have any layout it wants, and any controls.

However, you have shown me the light. The scroll pane by default only shows its scroll bars if needed. However, the panel inside has no controls, and therefore a preferred size of 0x0 (or something similarly small). Therefore, the panel will fit on your applet's content pane, and no scroll bars are needed.

There are three ways to get the scroll pane to be shown:
1) initialize the scroll pane with scrolling policies:

You can also set them using setHorizontalScrollBarPolicy and setVerticalScrollBarPolicy later.

2) add something to your panel that won't fit in your applet:


3) set the preferred size of the panel to a size bigger than the applet:



When the scroll bar policies are set to "AS_NEEDED", which happens by default, the scroll pane will use the panel's preferred size to determine whether or not to show the scroll bars. The panel's preferred size will be the size set using setPreferredSize (option 3), or if none was set the preferred size determined by its layout manager. The layout manager usually uses the components inside the panel for determining that preferred size.
 
shalini gnana
Ranch Hand
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you...The pane is showing now..But the problem is when i scroll down the drawing is going up..And if scroll up again the its not showing(drawing)..The same problem happens if i re-size my window..
[ October 21, 2007: Message edited by: shalini gnana ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic