Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2007

Tip: Looking for answers? Try searching our database.

JTable, JScrollPane & horizontal scroll bars - why?

Thread view: 
A. W. Dunstan - 09 Nov 2007 22:00 GMT
I need to display a JTable.  In this case the width of each cell in the last
column varies - it's a collection of text & color swatches, represented by
JLabels and JPanels stuffed into a containing JPanel.

I can get a vertical scroll bar to appear by putting enough entries in the
table, but no matter what the width of my columns it never puts in a
horizontal scroll bar.  Yes, I can force one by setting AUTO_RESIZE_OFF but
then I *always* get a horizontal scrollbar, even when I don't need one.
Also, the table always starts out much too narrow to display the entire
line, scroll bar or not.  I'd really like to get either a scroll bar, or
for the table to resize wide enough to show the longest line.

The least-worst solution I've found so far is to force a scroll bar and add
a ComponentListener to listen for changes in the size of the JComponent
containing the JScrollPane, and resize the width of the last column
accordingly.

Is there a better way of doing horizontal scroll bars in a JTable?

Signature

Al Dunstan, Software Engineer
OptiMetrics, Inc.
3115 Professional Drive
Ann Arbor, MI  48104-5131

Rich Sweeny - 10 Nov 2007 03:09 GMT
> I need to display a JTable.  In this case the width of each cell in the last
> column varies - it's a collection of text & color swatches, represented by
[quoted text clipped - 14 lines]
>
> Is there a better way of doing horizontal scroll bars in a JTable?

There are 3 constants:
    HORIZONTAL_SCROLLBAR_NEVER
    HORIZONTAL_SCROLLBAR_AS_NEEDED
    HORIZONTAL_SCROLLBAR_ALWAYS
    or
    VERTICAL_SCROLLBAR_NEVER
    VERTICAL_SCROLLBAR_AS_NEEDED
    VERTICAL_SCROLLBAR_ALWAYS

Example: This will always give you a vertical and never a horizontal:

JScrollPane scroll = new JScrollPane(table,
    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

Rich
A. W. Dunstan - 12 Nov 2007 17:18 GMT
>> I need to display a JTable.  In this case the width of each cell in the
>> last column varies - it's a collection of text & color swatches,
[quoted text clipped - 32 lines]
>
> Rich

The defaults for JScrollPane(Component) are *_SCROLLBAR_AS_NEEDED.  I needed
one, but never got one.

Signature

Al Dunstan, Software Engineer
OptiMetrics, Inc.
3115 Professional Drive
Ann Arbor, MI  48104-5131



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.