Solved

ScrollPane and Table

Posted on 2004-10-11
15
255 Views
Last Modified: 2010-08-05
Hello,
I have a table (colums and rows not fixed), but table's size is fixed. Now I want to have a scrollpane in both horizontal side and vertical size. I saw several examples which have a scrollpane just in vertical size.
For exp, my table have 20 colums, and 40 rows. Now, in viewport, we can see 10 colums and 20 rows, so I'd like to  use scrollpane to view all table.
Please help me as soon as possible
Thanks a lot
NN
0
Comment
Question by:nphnhi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
  • 2
15 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12275641
If you just place your table in a JScrollPane you should have vertical as well as horizontal scrollbars
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12275650
...automatically
0
 
LVL 37

Accepted Solution

by:
zzynx earned 100 total points
ID: 12275667
JScrollPane yourScrollPane = new JScrollPane();
yourScrollPane.setViewportView(yourTable);

whateverComponent.add( yourScrollPane );  // instead of yourTable
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 6

Expert Comment

by:expertmb
ID: 12275686
you can explicitly
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12275711
Not really needed.
The JScrollPane constructor without any paremeters creates a JScrollPane where both horizontal and vertical scrollbars appear when needed
0
 
LVL 6

Expert Comment

by:expertmb
ID: 12275731
i know that,
incase you want to have always then you can use above policy enforced.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12275770
>>incase you want to have always then you can use above policy enforced.
Incorrect. Then you can

yourScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
yourScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

( xxx_ALWAYS instead of xxx_AS_NEEDED)
0
 
LVL 6

Expert Comment

by:expertmb
ID: 12275795
>>Incorrect. Then you can
zzynx,
dont go by literally, what i said is you can explicilty set the scrollbar policy to ALWAYS
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS

and i know the syntax also.
0
 

Author Comment

by:nphnhi
ID: 12275834
No, I mean with 20colums, we can see 10 colums, and user srollbar (horizontal) to srcoll to view the rest
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12275842
Sorry, but this is what you said:

>>you can explicitly
>>JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
>>JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED

(remark:  xxx_AS_NEEDED)

I think a correction was needed for the author of this question not to be mislead. (no offence meant)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12275860
>> No, I mean with 20colums, we can see 10 colums, and user srollbar (horizontal) to srcoll to view the rest
The number of columns is irrelevant. The scrollbars will appear ***when needed***.
That means: as much columns as possible will be shown. The rest of the columns will be "reachable" by scrolling
0
 

Author Comment

by:nphnhi
ID: 12276105
I found an example :)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12276119
What do you mean by that?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java syntax, or is it Selenium 6 64
Eclipse Java import and method not resolved 4 141
What browser will run Java? 7 186
Netbeans and org.apache.commons.lang3 issue 3 55
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…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

710 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