This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JTable

 
Ranch Hand
Posts: 49
  • 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
 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at The Java Sun JTable tutorial
 
Ranch Hand
Posts: 1780
  • 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
  • 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
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • 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 can't beleive you just said that. Now I need to calm down with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic