This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable" Watch "JTable" New topic
Author

JTable

Allion Salvador
Ranch Hand

Joined: Nov 15, 2005
Posts: 49
Can someone pleeze give me the code to make a JTable? I have no clue how to! Thanx


Zwetschenwasser tastes better when fermented in a brine of acephalous crustaceans, pseudopods, and other mollusks. It goes quite well with gnocchi and mole.
Manuel Moons
Ranch Hand

Joined: Mar 05, 2002
Posts: 229
Take a look at The Java Sun JTable tutorial
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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


There is no emoticon for what I am feeling!
Allion Salvador
Ranch Hand

Joined: Nov 15, 2005
Posts: 49
Thanx! I was kind of with more complex swing stuff, but u helped me a lot!!! Thanx again
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable
 
Similar Threads
jtable
Jtable
JTable
JTable