aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes  jpane with scrollpane is not displaying Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark " jpane with scrollpane is not displaying" Watch " jpane with scrollpane is not displaying" New topic
Author

jpane with scrollpane is not displaying

shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
I tried to add jpanel with the scrollpane,but my scrollpane is not displaying...

Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
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.


bitguru blog
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

Also, don't forget to call super.paint(g) inside you're applet's paint method. Otherwise it won't refresh properly.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
Even now my scrollpane is not showing
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

You need to set the layout of the panel to border layout.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

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

Joined: Sep 18, 2007
Posts: 189
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.
 
subject: jpane with scrollpane is not displaying