• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

jpane with scrollpane is not displaying

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to add jpanel with the scrollpane,but my scrollpane is not displaying...

 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even now my scrollpane is not showing
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to set the layout of the panel to border layout.
 
Rob Spoor
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic