开发者

Use of mouselisteners in a jTable

开发者 https://www.devze.com 2022-12-27 15:22 出处:网络
I have a jTable with columns \'Job_no\' and \'Status\'with values such as: Job_noStatus 1Active 2Pending

I have a jTable with columns 'Job_no' and 'Status'with values such as:

 Job_no       Status 
 1            Active 
 2            Pending 
 3            Pending

I would like it so that if a user clicks on a St开发者_JAVA技巧atus say in this case the first 'Pending'(where Job_no = 2) an inputDialog pops up allowing the user to change the status of the cell clicked-how can I do this? Bear in mind you will also have to retrieve the Job_no(that corresponds to that status) somehow, and that, though I'm OK with JOptionPane's, I'm new to JTables. I'm using JDBC(mySQL) and have a table 'Jobs' which amongst other things, has column Job_no and status.

Thanks for your help.


You don't do that by using a mouse listener and a popup, you just make the cells editable, and perhaps set a custom TableCellEditor. Take a look at the Java Tutorial for more details.


1) add a MouseListener to the JTable
2) Read the JTable API for the methods that will convert a mouse point to a row/column
3) Now that you know the row/column you can use the getValueAt(...) method to query the data in the Job_no column
4) Then you can change the status of the selected cell using the setValueAt(...) method.

So you break the problem down one step at a time.

0

精彩评论

暂无评论...
验证码 换一张
取 消