JTable JComboBox change value behavior
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   David_Hardy
Posted On:   Thursday, November 1, 2001 09:47 AM

I have a JTable with a JComboBox in it. It has 3 rows. When I click on the 1st row's combobox, and click on a value down in the list, that selection becomes selected. When I select a combobox in either of the other 2 rows, I cannot make an item in the list be selected without 'dragging' my mouse onto the selection. In other words, I can't click to make a selection, I have to drag to make a selection. When I do click on these other rows, the setValueAt(...) method does't even get called. I am at a total loss how rows could act differently in this manner. If anyone knows why this is happening I would greatly appreciate an explanation. Thank You, Dave    More>>

I have a JTable with a JComboBox in it. It has 3 rows. When I click on the 1st row's combobox, and click on a value down in the list, that selection becomes selected. When I select a combobox in either of the other 2 rows, I cannot make an item in the list be selected without 'dragging' my mouse onto the selection. In other words, I can't click to make a selection, I have to drag to make a selection. When I do click on these other rows, the setValueAt(...) method does't even get called.


I am at a total loss how rows could act differently in this manner. If anyone knows why this is happening I would greatly appreciate an explanation.


Thank You,


Dave

   <<Less

Re: JTable JComboBox change value behavior

Posted By:   kamlesh_patel  
Posted On:   Friday, November 9, 2001 12:33 PM


I had a similar problem and it works fine for me. I am providing u a skeleton of what I did.
I had two columns with combobox. The first column consists of project names & another column
having module names. So when a user selects a project name in 1st column the value of
module combobox changes automatically.

Hopefully this code will help you ..


tableReference.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseMoved(java.awt.event.MouseEvent evt) {
jTableMouseMoved(evt);
}
});



private void jTableMouseMoved(java.awt.event.MouseEvent evt) {

Point p = evt.getPoint();
int row, col;

row = tableReference.rowAtPoint(p);
col = tableReference.columnAtPoint(p);

projectname = (tableReference.getValueAt(row,0)).toString();

if (projectname.trim().length() == 0)
return;

switch(col){
case 1:
javax.swing.JComboBox temp_col = new javax.swing.JComboBox();
// ... select values for project names &
//... add your items in temp_col.....

tableReference.getColumn("MODULE").setCellEditor(new DefaultCellEditor(temp_col));
break;

} // switch
}


Thanks

Kamlesh

About | Sitemap | Contact