Solved

JTable

Posted on 2000-04-13
6
451 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Jpanels and Jframe 8 33
netstat -ano | find "8000" and taskkill /f /pid 2984 3 57
how to add new optional parameter to JSP 1 42
Android development question 2 38
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

822 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