Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTable: how to get data of a selected row

843804Apr 7 2005 — edited Apr 13 2005
hi
everybody.
i have created a JTable, and now i want to get the data of a particular selected row.
i want to store that data in a string or an array.
i have tried with ListSelectionListener where currently i am getting only the index of the row selected. but how to get the data of that row.
the following is my code for ListSelectionListener
      if (ALLOW_ROW_SELECTION)
        {
			// true by default
            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())
                    {
                        System.out.println("No rows are selected.");
                    }
                    else
                    {
                        int selectedRow = lsm.getMinSelectionIndex();
                        System.out.println("Row " + selectedRow + " is now selected.");
                    }
                }
            });
        }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 11 2005
Added on Apr 7 2005
7 comments
963 views