Improve company productivity with a Business Account.Sign Up

x
  • 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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