Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to add jcolumn  RSS feed

 
ali ak
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a jtable with two columns so I need add checkboxes dynamically in to the first column.Bıt I couldn find something like add.How can do this.This is what I have so far


 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't remember anything about JTables. Have a look at the Java Tutorials and see whether that helps.

I shall move this discussion to our GUIs forum.
 
ali ak
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you .after 3 hours later I was able to add checkboxes to the first column.But this time I cant add rows to the second column .I am so confused.


 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't create your own TableModel. Just use the DefaultTableModel.



If you want to add a row of data to the table then you do something like:


 
ali ak
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob thank you for your help I have changed my code as you suggested and it's very close what I want do.I have two problems Firstly I have an ArrayList named GetRows .How can I add theese values to the second column The other Problem is checkboxes are not clickable.This is what I have tried so far


 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an ArrayList named GetRows .How can I add theese values to the second column


If you have an ArrayList with data then you need to create a loop and add one row at a time as you iterate through the ArrayList.

> The other Problem is checkboxes are not clickable.This

You probably need to assign the Boolean editor to the column the same way you assigned the renderer.

Or, the other approach is to override the getColumnClass() method of your table model to return Boolean.class for the first column. Then the table will choose the proper renderer and editor so you don't need to do it manually.
 
ali ak
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you rob
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!