JScrollpane center alignment

122 views
Skip to first unread message

Kurt Latre

unread,
Feb 21, 2012, 5:09:24 AM2/21/12
to AsWing Discuss

I have a panel that is populated with dynamicly generated data-
options.
Most of the time, the number of data-options is big, so I need a
scrollpane to let the user see them all.
But there are some cases where where the amount of objects is rather
small.
Then, the objects are showed centered in the scrollpane
This make the GUI look weird
I'ld like to see this content on top of the panel.
But somehow, the JScrollpane always centers the content.


Is there a way to avoid center alignment in the JScrollpane.

iiley

unread,
Feb 22, 2012, 2:17:15 PM2/22/12
to aswing-...@googlegroups.com
See the 2rd and 3th param of JViewport constructer

2012/2/21 Kurt Latre <meeste...@gmail.com>



--
-iiley
Burstyx Studio Limited

Daniel Kvarfordt

unread,
Aug 23, 2012, 9:21:03 AM8/23/12
to aswing-...@googlegroups.com
I had the same problem, but setting trackHeight on the viewport to true made the scrollbars disabled. 
Calling setVerticalAlignment(TOP) on the viewport fixed it though.
(posting my solution if anyone has the same problem)

someprogrammer

unread,
Sep 5, 2012, 11:13:16 AM9/5/12
to aswing-...@googlegroups.com
here some example code:
contactsListContainer=new JScrollPane(contactsList, JScrollPane.SCROLLBAR_ALWAYS, JScrollPane.SCROLLBAR_NEVER);
JViewport(contactsListContainer.getViewport()).setVerticalAlignment(JViewport.TOP);

works fine for me
Reply all
Reply to author
Forward
0 new messages