Solved

Using JScrollPanes

Posted on 2000-03-09
4
273 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 98
Custom Java Application connects to database: Which one of the 20? 4 29
SHA2 certs for IIS AND Java? 2 94
Error in @AspectJ Based AOP with Spring 2 13
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

803 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