This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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

Understanding JTable.addColumn()

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello folks,

this is a hacky approach at understanding swing's JTable, based on Sun's Demo Application. After clicking into the table, a new column is added and displayed (my custom datamodel registers as listener to the columnAdded-Event). I'm expecting to have cell-value for this new column = "argh" but the value is the same as it is for the first column (Mary). I don't get this. What am I missing here? The TableDemo.debugColumnAdd output at least assumes that argh is returned for the new column. So why/how are the renderers calling tableModel.getValueAt(...)? Instead of using columnIndex 5 they wrap back to 0.

The main class:


My custom tableModel:
 
Stephan Mueller
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solution:
TableColumn foo = new TableColumn(); creates a new TableColumn with a model index of 0! That's why the code always returns Mary (getValueAt(0,0)) instead of the expected argh (getValueAt(0,5))
TableColumn foo = new TableColumn(5); is the solution for adding one column, otherwise TableColumn foo = new TableColumn(tableModel.getColumnCount); would be for adding arbitrary numbers of columns.
 
Then YOU must do the pig's work! Read this tiny ad. READ IT!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic