This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create and dynamically change buttons in jtable column

 
Ruchi Kumctr
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a lot of problems fully grasping tablecellrenderer and tablecelleditor. I have researched a lot, looked in a lot of forums, but still can't solve my problem.
Without posting an sscce (because my code is probably very incorrect), how would I do the following:
Create a jtable with a column that has ButtonX in it. Then when another column in a specific row gets a certain value, ButtonX will change to ButtonY, but other rows will remain what they are already. In the following example, all rows started with ButtonX, but when Progress changed from Uploading to Complete, ButtonX became ButtonY.

Row Name Progress Abort/Complete
0 File 1 Complete ButtonY
1 File 2 Complete ButtonY
2 File 3 Uploading ButtonX

The buttons need to update accordingly if a row is deleted. For example if row 0 is deleted, it should look like:
Row Name Progress Abort/Complete
0 File 2 Complete ButtonY
1 File 3 Uploading ButtonX
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from your description you only need the renderer where you override
getCellRenderer(int row,int column)
to return a buttonRenderer if the column is [whatever the button column is] e.g. 3

and in your buttonRenderer you create/return a JButton with initial text of "ButtonX",
and if the value of the cell at column [whatever] .equals([a certain value]),
the button text changes to "ButtonY".
 
Ruchi Kumctr
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That makes sense. Thanks! The only thing now is that the first time, I get the correct button. However, after my progress changes, I don't get an update in button until I click on the table (or anywhere on the applet for that matter). How do I make it programmatically update the table?
 
Ruchi Kumctr
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just repainted the table in order to update the table. But now my button is not clickable. All the forums I'm looking at say that I need to do the same thing in my tablecelleditor as in my tablecellrenderer. Is that true?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you need the button to do something, you'll need the editor
 
Ruchi Kumctr
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic