SaketM
asked on
JTable
I am using vector for populating the JTable. How will i give the option to the user to modify the a particular row and save it back to the vector.
Thanx
Thanx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Which event of JTable i have to implement to get the row clicked and retreive the data.
public boolean isCellEditable(int row,
int column)from DefaultTableModel
tells if the cell from row and column is editable. You have to do overwrite
this function in your TableModel and
to tell explicitly what cell is editable and what cell is not.
concerning the other issue:
public void setValueAt(Object aValue,
int row,
int column)
from the DefaultTableModel is called avery time the user enter a new value for a cell. If you overwrite this function also you'll be able to know every time when the user tries to change
a cell value
int column)from DefaultTableModel
tells if the cell from row and column is editable. You have to do overwrite
this function in your TableModel and
to tell explicitly what cell is editable and what cell is not.
concerning the other issue:
public void setValueAt(Object aValue,
int row,
int column)
from the DefaultTableModel is called avery time the user enter a new value for a cell. If you overwrite this function also you'll be able to know every time when the user tries to change
a cell value
ASKER
But how will i get the row which the user clicked. For that i need to some which listener.
jTable.addMouseListener
(
new java.awt.event.MouseAdapte r( )
{
public void mouseClicked( java.awt.event.MouseEvent evt )
{
jTableMouseClicked( evt );
}
}
);
private void jTableMouseClicked( java.awt.event.MouseEvent me )
{
// find the cell
int row = jTable.getSelectedRow( );
int col = jTable.getSelectedColumn( );
if ( me.getModifiers( ) == me.BUTTON1_MASK )
{
// add code for first mouse button
}
if ( me.getModifiers( ) == me.BUTTON3_MASK )
{
// add code for second mouse button
}
}
(
new java.awt.event.MouseAdapte
{
public void mouseClicked( java.awt.event.MouseEvent evt )
{
jTableMouseClicked( evt );
}
}
);
private void jTableMouseClicked( java.awt.event.MouseEvent me )
{
// find the cell
int row = jTable.getSelectedRow( );
int col = jTable.getSelectedColumn( );
if ( me.getModifiers( ) == me.BUTTON1_MASK )
{
// add code for first mouse button
}
if ( me.getModifiers( ) == me.BUTTON3_MASK )
{
// add code for second mouse button
}
}
ASKER
Thanx