• Post Reply Bookmark Topic Watch Topic
  • New Topic

user select jtable row  RSS feed

 
randy butler
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranchers, I'm confused..... In my jtable i want the user to select the row, and hit edit button then that selected rows data will show up in the text fields of the edit dialog window. not sure how to go about getting the data from the table to the text fields?

thank you
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTable's getValueAt method looks like a good idea.
 
randy butler
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob thanks for the info. should I just add table.getModel().getValueAt(row_index, col_index) to the edit button method?
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTable has its own getValueAt method, which it actually delegates to the model. The difference is the ordering of columns and hiding of rows (the latter since Java 6). There are some methods in JTable for converting a JTable row / column number to a model row / column number and vice versa. The great thing is, if you use JTable's getValueAt, that conversion will be done in the background.
 
randy butler
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob, I'm using the following and able to get one cell


is there a way to collect the entire row?

thanks
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get each cell from the row. You know how many there are, from the TableModel.
 
randy butler
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob, I think i got it figured out I need to do something like this.

int n = PartToolOrderTable.getSelectedRow();


String txtId = (String)PartToolOrderTable.getValueAt(n,0);
String requester = (String)PartToolOrderTable.getValueAt(n,1);
String servnumber = (String)PartToolOrderTable.getValueAt(n,2);
String sonumber = (String)PartToolOrderTable.getValueAt(n,3);

am i correct?

thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!