Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JTable

Posted on 2000-04-13
6
Medium Priority
?
456 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 200 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

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 …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

688 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