File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can U Turn a JTable Sideways?

 
Bob Nedwor
hangman
Ranch Hand
Posts: 215
Eclipse IDE Oracle Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bob Nedwor
hangman
Ranch Hand
Posts: 215
Eclipse IDE Oracle Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You so much, Jeff! You're the man!!!
--
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic