File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes valueChange in a ListSelection when i Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "valueChange in a ListSelection when i " Watch "valueChange in a ListSelection when i " New topic
Author

valueChange in a ListSelection when i

ben chato
Greenhorn

Joined: Jul 10, 2001
Posts: 4
Hi !
I've got a problem with my JTable.
Normally, when we click on a row, its background becomes blue (it is now selected !)
But, when the cellEditor is a JComboBox, even if i change the value in the 3rd row, table.getSelectedRow() still returns 0. (and the first row is still blue).
How can i get the row index of the JComboBox i clicked and force the selectedRow ?
thanks !
Ben
------------------
SAFROLE YUTANI
Ranch Hand

Joined: Jul 06, 2001
Posts: 257
Add a listener to the JComboBox. When its value changes, update your table to select the row in which the JComboBox resides. The problem is trying to determine the row number that the JComboBox is in, because that's the row that you have to select after the JComboBox's value changes.
SAF
ben chato
Greenhorn

Joined: Jul 10, 2001
Posts: 4
Yes... that's the problem ! :-)
i'm still searching...
Ben
SAFROLE YUTANI
Ranch Hand

Joined: Jul 06, 2001
Posts: 257
If you're adding the JComboBox's dynamically, meaning that your application will add a variable amount of JComboBox's to your JTable, then just subclass JComboBox and add a new attribute that stores the row number in which the combox box is located in your JTable. Add a method to your new class that will allow the JTable to get the row number from the combo box, then you will know the row to select.
SAF
ben chato
Greenhorn

Joined: Jul 10, 2001
Posts: 4
Thanks, it could be a good idea but i think it won't work.
My JComboBox are not placed dynamically : i use them as a DefaultCellEditor for my Column.
Ben
ben chato
Greenhorn

Joined: Jul 10, 2001
Posts: 4
I finally found the answer :
1- I placed a mouseListener on the JTable
2- When i click on a cell, the mousePressed tell me the point.
3- I get the rowAtPoint()
4- I send the focus on the row with :
try {
table.editCellAt(line,0);
table.getEditorComponent().requestFocus();
lsm = table.getSelectionModel();
lsm.setSelectionInterval(line,line);
} catch (Exception ex) {
...
}
that's all !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: valueChange in a ListSelection when i
 
Similar Threads
JComboBox: Opaque problem
Using JCheckBox as CellRenderer in JComboBox
JComboBox in the JTable Editor
Action listener for JTable row selection event
Obtaining the value of a row from a JComboBox