• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

valueChange in a ListSelection when i

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
------------------
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes... that's the problem ! :-)
i'm still searching...
Ben
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !
 
reply
    Bookmark Topic Watch Topic
  • New Topic