aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Can U Turn a JTable Sideways? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can U Turn a JTable Sideways?" Watch "Can U Turn a JTable Sideways?" New topic
Author

Can U Turn a JTable Sideways?

Bob Nedwor
hangman
Ranch Hand

Joined: Aug 17, 2005
Posts: 215

Looked through the http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JTable.html and the Sun tutorial on JTables, but I could not find a way to do this. I need my attribute names down the side along the first column, not along the top of the first row. The number of rows would always be the same, but as I add records the number of columns would grow. This would need a scroll bar along the bottom rather than along the right side.

Thanks for any suggestions..
--Bob


Bob N
SCJP - 1.4
SCJD - (B&S) Used 1.5 And It Runs On Solaris10
SCWCD - Thanks to HFSJ!!
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
This is mainly a matter of working with your JScrollPane and tweaking JTable properties. A JScrollPane is divided into 9 regions, like a tic-tac-toe game, with the center region dominating. When you put a JTable into a JScrollPane, the table itself is displayed in the center region (the viewport), in the center north region your JTable's JTableHeader is displayed, and scroll bars can appear in the center right and bottom center regions. To get what you want (row headers) you need to put a second JTable, containing your row header elements as a single column of data, into the row header view of the JScrollPane. You can also eliminate the column headers from the main table by setting the JScrollPane's column header view to null.

If you Google, you should be able to find an example of doing this, it is a common technique. Java Almanac is another good resource: http://javaalmanac.com/egs/javax.swing.table/pkg.html

Here's a quick demo I just whipped up:
[ January 13, 2006: Message edited by: Jeff Albrechtsen ]

There is no emoticon for what I am feeling!
Bob Nedwor
hangman
Ranch Hand

Joined: Aug 17, 2005
Posts: 215

Thank You so much, Jeff! You're the man!!!
--
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
 
Don't get me started about those stupid light bulbs.
 
subject: Can U Turn a JTable Sideways?