Solved

Using JScrollPanes

Posted on 2000-03-09
4
275 Views
Last Modified: 2012-05-05
Check out the code below and see if you can tell me why my windows don't show the ScrollPane the way it's supposed to:

Border compound = BorderFactory.createEmptyBorder(0,10,10,10);

ev = new EventView(jDateTree, top, thisDateHash);  // returns a JPanel
jEvent Panel = new JPanel();
jEventPanel.setBounds(0,0,780,getHeight());
jEventPanel.setLayout(null);

ev.setLayout(null);
ev.setBounds(170,30,500,getHeight()-30);
ev.setBorder(compound);

JScrollPane evScrollPane = new JScrollPane(ev);

JEventPanel.setPrefferredSize(new Dimension(getWidth() - 170, getHeight() - 30));
evScrollPane.setBounds(170,30,1000,getHeight()-30);
jEventPanel.add(evScrollPane);
JEventPanel.setBorder(compound);


My applet compiles and runs fine. It shows what it is supposed to, but there is only one scrollbar at the bottom of the applet.  This should be a simple task, yet I don't know why it's not working.  Could someone please help!!!????The element that is supposed to be scrolled is a JPanel, and I know it's legal to have a JPanel inside a scroll pane right?
0
Comment
Question by:tblackwe
4 Comments
 
LVL 2

Expert Comment

by:stalefish
ID: 2602736
I believe by default that the scrollbars in scrollpane are only shown when necessary. If you want them to be visible always, you have to explicitly tell it that by using

JScrollpane.setVerticalScrollBarPolicy(int policy);
and
JScrollPane.setHorizontalScrollBarPolicy(int policy);

Dustin
0
 
LVL 6

Expert Comment

by:expertmb
ID: 2604311
hi,
 try this

     evScrollPane.getViewport().add(parameter, null);
     parameter = e.g., list,table

mb...
0
 
LVL 1

Expert Comment

by:David MacDonald
ID: 2605663
Stalefish has it, you have to explicit them if you want to view them...
0
 
LVL 2

Accepted Solution

by:
AlexJ030200 earned 50 total points
ID: 2617993
It would be a good idea if you call
ev.revalidate();
after changing sizes.

From the java tutorial:

"Changing the size of a scroll pane's client is a two-step process. First, set the client's preferred size. Then, call revalidate on the client to let the scroll pane know that it should update itself and its scroll bars."


hope this helps.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question