java - how to select an object from a jTable by a click -
i have made class called clients, has simple attributes client_id, client_name , client_age. have programmed small gui netbeans after input data client pressing button displayed in jtable.
the source code adding in jtable is:
for (int i=0;i<customerv.length;i++){ jtable2.setvalueat(customerv[i].getname(), i, 0); }
i if click 1 element on jtable able add orders client making using of jbutton. if program in console like:
order order1=new order("1000","41211")
in first field order id , second order number, if want assign customer 1 like.
c1.assignorder(order1)
how can using java swing? mean select whole object element click in jtable
- set instances of
clients
table model instead of client names (like:jtable2.setvalueat(customerv[i], i, 0);
) - implement custom renderer render client class needed (e.g. display client's name) , set table. (easier) option override
tostring
onclients
return client's name, or whatever want displayed , not bother renderer. - call
getvalueat()
clients
instance bound particular cell in button click handler.