1

I have to develop a front end in Swing.I have a JFrame in Netbeans with 3 panes in it.

  • JScrollPane 1:it contains a JTable
  • JScrollPane 2: It should display the value of the fields of the selected row
  • ListPane : which contains the list of tables from which a user chooses a table to be displayed.

Now since the content of JTable varies(the no of rows and columns also vary) dynamically based on the table chosen by user I can't drag and drop the TextBoxes in the 3rd scroll pane to display the selected row's values.It would be helpful if anybody can suggest a way to do it or any pointers to problems that deal with similar issue

mKorbel
  • 109,525
  • 20
  • 134
  • 319

1 Answers1

1

Add a ListSelectionListener to your JList. When a particular table is selected from the list, use setModel() to change the TableModel of your JTable to one that is correct for the chosen table. A related example using setModel() is shown here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • is it possible to do it in a simpler way??i found [this](http://stackoverflow.com/questions/9080687/show-data-from-jtable-in-jtextfield-with-2-jframes) to be useful. so that i have to create as many textboxes as the columncount that is selected and display the respective values. – user2083089 Feb 28 '13 at 12:52
  • Not that I know. A `ListSelectionListener` works on a JTable, for [example](http://stackoverflow.com/a/12306104/230513). – trashgod Feb 28 '13 at 13:13