• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with Custom JTable Renderer and Cell Editor  RSS feed

 
Nate Atkins
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I'm trying to do is make an inventory type program that includes a jtable. In the Jtable in the last column there will be 2 buttons and a textfield to register the value of additions or subtractions to the overal stock amount. (See screenshot in attachment).

As of now I am able to increment or decrement the numbers when the buttons are clicked on however the problem is that if I add 2 to the first row, and then go to add 2 to the next row or any other row for that matter, the value of the previous row is added to the next row, and the previous row reverts back to a value of 0. So basically its like there is only one editor that keeps track of one value no matter what row you are editing.

I need help getting it so that I can add different values to each different row depending on the stock being used or received. The following is my code:

Main class



Cell Renderer



Cell Editor



Custom Component


I appreciate any input or help that will get me going in the right direction.

Thanks
2014-07-22_0736.png
[Thumbnail for 2014-07-22_0736.png]
Screenshot of table
 
m beardsley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does your table model look like? Make sure you have a spot for the integer you're letting the user edit and that you have a setValueAt method to change the value in the model once the cell editor finishes its job.

You need to have your cell editor return the value in the text box. You're returning an empty string from getCellEditorValue() you should be returning change.getText() or Integer.valueOf(change.getText()).
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
M Beardsley: welcome to the Ranch
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!