File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Jtable Event Handling

Kamlesh Sangani

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

Joined: Apr 09, 2004
Posts: 5
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

Joined: Feb 17, 2004
Posts: 6
This example is from 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.
//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 =
if (lsm.isSelectionEmpty()) {
...//no rows are selected
} else {
int selectedRow = lsm.getMinSelectionIndex();
...//selectedRow is selected
John Wetherbie

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

The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
I agree. Here's the link:
subject: Jtable Event Handling
It's not a secret anymore!