I have One Jtable in which i have added JComobox like this.
TableColumn sportColumn = jTable1.getColumnModel().getColumn(2);
comboBox = new JComboBox();
comboBox.addItem("Snowboarding");
comboBox.addItem("Rowing");
comboBox.addItem("Chasing toddlers");
comboBox.addItem("Speed reading");
comboBox.addItem("Teaching high school");
comboBox.addItem("None");
sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
and i have added one mouse event of jtable like this.
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
try {
int row = jTable1.rowAtPoint(evt.getPoint());
int col = jTable1.columnAtPoint(evt.getPoint());
System.out.println("Row" + row + "Column" + col);
} catch (Exception e) {
e.printStackTrace();
}
}
and i am getting proper out put of row and column.
but when i click on the cell where i added Jcombobox that time its not giving out put of that row and column. still i have called clickevent of table in combobox click event but its giving all time row 0 and even column 0 here screen shot.
so how do i solved it so i can have that row and column?
Using below code you can get values of selected rows and column.
check with mouselistner with your jtbale.
UPDATE : add this two line before printdebugdata() called.
I got the row number check my output.
OUTPUT :
Thanks..
As I see it, you have three basic options...
You Could...
Attach a
CellEditorListener
to theDefaultCellEditor
and monitor foreditingStopped
events...The problem with this, is it's not possible to actually determine the cell that's been edited. Even with a reference to the
JTable
, by the time you receive this event, the table is no longer in edit mode...So all you know is the value of the editor...You Could...
Attach a
TableModelListener
to theTableModel
...This will let you know when the value of a cell has changed (and a lot of other things, but this is what we're interested), what it won't tell you, is why it changed.
This approach is good, because it provides all the information you need to know in order to find the value and the cell.
You Could...
Simply override the
TableModel
'ssetValueAt
method and provide some sort of notification of your own...While this is kind of duplicating the functionality of the
TableModelListener
you could devise the event information so that it provides more relevant information as theTableModelEvent
covers a lot of user cases...Example
Below is an example taken TableRenderDemo and modified to to demonstrate the first two concepts
Well Its Little But strange for me but ya i do solved it but i dont think so that is the proper ansewer but i solved it. i called. Combo button Action Performed event and have called Mouse click of jtable in that. with null instead of the Event. check it out.
may be its not Right way but i solved it this threw. its working.
best solution is