Solved

Using JScrollPanes

Posted on 2000-03-09
4
271 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
Comment Utility
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
Comment Utility
hi,
 try this

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

mb...
0
 
LVL 1

Expert Comment

by:David MacDonald
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java virtual machine monitoring tools 3 39
countPairs challenge 7 57
wordlen challenge 3 46
mockito example issue 8 26
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now