File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Jtable Event Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jtable Event Handling" Watch "Jtable Event Handling" New topic
Author

Jtable Event Handling

Kamlesh Sangani
Greenhorn

Joined: Feb 28, 2004
Posts: 22
How can i handle the event of JTable? like when user clicks particular row which event is fired???


Lets Java !<br />Kamlesh
cassie williams
Greenhorn

Joined: Apr 09, 2004
Posts: 5
hi,
i'm new in java, maybe you can try this?
in actionPerformed method, do
if(e.getSource() == button1){do something}
else if(e.getSource() == button2 {do something else}
else if .....
Polina Bee
Greenhorn

Joined: Feb 17, 2004
Posts: 6
Hi.
This example is from sun.java Swing tutorial:
Detecting User Selections
The following code snippet shows how to detect when the user selects a table row. By default, a table allows the user to select multiple rows � not columns or individual cells � and the selected rows need not be next to each other. Using the setSelectionMode method, the following code specifies that only one row at a time can be selected.
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
...
//Ask to be notified of selection changes.
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
//Ignore extra messages.
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm =
(ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty()) {
...//no rows are selected
} else {
int selectedRow = lsm.getMinSelectionIndex();
...//selectedRow is selected
}
}
});
John Wetherbie
Rancher

Joined: Apr 05, 2000
Posts: 1449
Polina B,
Please change your displayed name to follow the JavaRanch naming policy. You can do this here.
Thanks.


The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jtable Event Handling