Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable Columns

 
Richard West
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I am currently trying to limit the number of columns that can be added to a JTable by a user.

You see at first i add the user can dynamically add Columns to the JTable like how i did below



now it seems that after i reach 5 columns i cannot add any more columns which is correct
but after deleting some columns to 3 columns, i should be able to add some columns bu it seems that i smply cannot add any more columns

It seems that the following command line
TableModel1.getColumnCount();
seems to always be the number 5. Even when i delete all columns the above method still gives me the number 5.

This is how i delete the columns dynamically



Why does this happen?
Am i doing something wrongly?

I hope someone can help me with this problem

Thank You

Yours Sincerely

Richard West
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The table (view) listens to the model. The model can tell the table to update its view to reflect changes in the model. You did that in the insertcolumn method.
The model does not listen to the table (view). When you make changes to the view the model is not informed. Make arrangements to update the model in deletecolumn.
 
Richard West
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

Originally posted by Craig Wood:
Make arrangements to update the model in deletecolumn.[/QB]


I did the below but it still did not work and i got the same problem



Am i doing the updating wrongly?

If its of no inconvnience for you could you show me the correct way of doing the updating after deleting the columns

Hoping to hear from you

Yours Sincerely

Richard West
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The TableModel has not been updated yet so there will be no change.
There is an example here: Removing a Column from a JTable Component.

edit: formatting
[ April 01, 2006: Message edited by: Craig Wood ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!