Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2005

Tip: Looking for answers? Try searching our database.

JScrolPane

Thread view: 
bnlfan64@yahoo.com - 06 Jan 2005 22:27 GMT
This is my first attept at using a JScrollPane.  My goal is to have a
component of some sort (I'm currently using JPanel) that I can set to a
certain size and draw on.  I add the component to a JScrollPane since
the size of the Panel will more the likely be larger then the JFrame.
The problem I have right now is that the JPanel that the scroll pane is
holding onto resizes itself with everything else and I never get the
scroll bars.

Code:

TestPanel panel = new TestPanel(); //just a JPanel with some
logic for pait method

scroller = new JScrollPane();
scroller.setViewportView(panel);
scroller.setPreferredSize(new Dimension(300,200));
test_frame = new JFrame();
test_frame.setLayout(new BorderLayout());
test_frame.add(scroller,BorderLayout.CENTER);
test_frame.setSize(150,150);
test_frame.setVisible(true);
Any and all help appreciated.
Thanks,
Adam
klynn47@comcast.net - 07 Jan 2005 03:26 GMT
I would try creating the JScrollPane using the panel,

scroller = new JScrollPane(panel),

and then calling the methods setPreferredSize and revalidate on the
panel.
Andrew Thompson - 07 Jan 2005 08:18 GMT
> TestPanel panel = new TestPanel(); //just a JPanel with some

The problem most likely originates from this line, or rather,
the TestPanel that you refer to but don't include[1].

klynn is on the right track, I think, from the little you have told
us, but the setting of sizes is most logically put within the TestPanel
itself.

[1] <http://www.physci.org/codes/sscce.jsp>

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

ckumar - 12 Jan 2005 10:40 GMT
Hai,

I never used scrollpane for a JPanel.But I used for JLabel, JTable. I
normally add the component to the JScrollPane.

Try this following code.

TestPanel panel = new TestPanel();

int vs =ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int hs =ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
scrollpane=new  JScrollPane(panel,vs,hs);

test_frame = new JFrame();
test_frame.setLayout(new BorderLayout());
test_frame.add(scrollpane,BorderLayout.CENTER);
test_frame.setSize(150,150);
test_frame.setVisible(true);
test_frame.pack();

ackumar


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.