Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable

 
Allion Salvador
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone pleeze give me the code to make a JTable? I have no clue how to! Thanx
 
Manuel Moons
Ranch Hand
Posts: 229
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at The Java Sun JTable tutorial
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact, given your recent posts about help with GridBagLayout and JTabbedPane,
you should check out Sun's tutorials from the top:
http://java.sun.com/docs/books/tutorial/index.html
 
Allion Salvador
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx! I was kind of with more complex swing stuff, but u helped me a lot!!! Thanx again
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the thing to remember about JTable, is that you have your JTable, which sets the JTable up in terms of ColumnModels and Editors and Renderers. When a JTable is displayed, without any row/column selected, the visible data is displayed with each columns own renderer. If you don't create or supply your own, then the default ones are used. This is the same as the Editors, but the editor is only visible when you are actually in that column. I say column because both editors and renderers are set to the ColumnModel. So the Edit that is set in the ColumnModel is what is displayed when you are editing a Cell.

You can create your own Editors and Renderers all you want and do some cool stuff.

The second thing to know about creating JTables is that you have a TableModel. usually by extending DefaultTableModel or AbstractTableModel, you set the column names, and the classes that each column holds. like String or Integer or Date. This is what helps tell the JTable which default renderer and editor to use. You can also overwrite things like setValueAt(row, column) and getValueAt(row, column) Which allows you to put anytype of class in your TableModel to represent the data, rather than having to use a two dimensional array. So if you have a List of Dogs with Dog Name, Dog Type, Age. You can have a Dog class with those attributes, then have the TableModel hold a List<Dog>. Then in the getValueAt() you would take the row parameter and List<Dog>.get(row); and then based on the Column number get the corresponding Dog attribute. And reverse with setValue At except the List<Dog>.get(row),

Usually it is a good idea to use CONSTANTS to map the column number to a meaningful name. I will post a complete example when I get into work.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic