• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

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
0
SaketM
Asked:
SaketM
  • 3
  • 3
1 Solution
 
ovidiucraciunCommented:
Set your table model as DefaultTableModel and take advantage of the
"protected Vector dataVector"
data member. A reference to this member you can obtain with member function public Vector getDataVector().

0
 
SaketMAuthor Commented:
I need more descriptive answer. I am new to JTable so please send some code if possible
Thanx
0
 
SaketMAuthor Commented:
Which event of JTable i have to implement to get the row clicked and retreive the data.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ovidiucraciunCommented:
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

0
 
SaketMAuthor Commented:
But how will i get the row which the user clicked. For that i need to some which listener.
0
 
ovidiucraciunCommented:
jTable.addMouseListener
(
      new java.awt.event.MouseAdapter( )
      {
            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
      }
}
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now