Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-28-2007, 03:54 PM
Member
 
Join Date: Jun 2007
Location: Colombo, Sri Lanka
Posts: 32
hiranya is on a distinguished road
Scrolling with JTables
Hi everyone,

I'm fairly new to building GUIs with Java. I'm trying to display the contents of a database table using a JTable object. The table has 13 columns. So I want the user to be able to scroll horizontally to see all the columns in the JTable object. Can anyone give me an example code segment that fits this scenario.

(All the data retrieval tasks are working fine. I just want the user to be able to scroll. The code I have written displays all the 13 columns in the viewable area of the JTable by reducing the column widths.)

Regards,
Hiranya
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-28-2007, 11:29 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
Mount the JTable in a JScrollPane. Since JTable implements the Scrollable interface a parent scrollPane will have access to all the information it needs to properly show the table You can specify the preferred viewport size with the JTable setPreferredViewportSize method.
Code:
JTable table = yourTable // provide a size hint Dimension d = table.getPreferredSize(); d.width = as you like d.height = ... table.setPreferredScrollableViewportSize(d); getContentPane().add(new JScrollPane(table));
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-29-2007, 12:45 PM
Member
 
Join Date: Jun 2007
Location: Colombo, Sri Lanka
Posts: 32
hiranya is on a distinguished road
Thanks....
I would also like to know how to make the contents in a JTable read only.

Regards,
Hiranya
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-29-2007, 09:30 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
Disabling User Edits in a JTable Component
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-30-2007, 08:34 AM
Member
 
Join Date: Jun 2007
Location: Colombo, Sri Lanka
Posts: 32
hiranya is on a distinguished road
Is there a way to programmatically select a row in a JTable? I want the first row of the table to be selected by default when the table loads.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 10-30-2007, 10:48 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
Yes. You can do it through the tables SelectionModel or you can use the JTable convenience method
Code:
changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
See api for use of the boolean flags.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to make a JDialog scrolling from one position to the other. Eranga AWT / Swing 1 03-28-2008 12:26 PM
Applet with scrolling status line Java Tip Java Tips 0 03-10-2008 04:53 PM
AWT Table Scrolling albert_kam AWT / Swing 0 01-03-2008 01:37 PM
MouseMotionListener 'scrolling' Thez Java 2D 0 12-20-2007 01:21 AM
JScrollPane not scrolling Riftwalker Advanced Java 2 07-17-2007 10:16 PM


All times are GMT +3. The time now is 03:43 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org