Solved

JTable

Posted on 2000-04-13
6
455 Views
Last Modified: 2008-03-03
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
Comment
Question by:SaketM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 3

Accepted Solution

by:
ovidiucraciun earned 100 total points
ID: 2712476
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
 

Author Comment

by:SaketM
ID: 2712507
I need more descriptive answer. I am new to JTable so please send some code if possible
Thanx
0
 

Author Comment

by:SaketM
ID: 2712514
Which event of JTable i have to implement to get the row clicked and retreive the data.
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 3

Expert Comment

by:ovidiucraciun
ID: 2712617
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
 

Author Comment

by:SaketM
ID: 2714593
But how will i get the row which the user clicked. For that i need to some which listener.
0
 
LVL 3

Expert Comment

by:ovidiucraciun
ID: 2715354
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question