0

I'm working on a small File Management program in Eclipse(Version:Kepler). Also am new to Java Programming.

I designed a JPanel in a JFrame, where there are two JScrollPanes each containing a JList. The two JLists are programmed to show a list of files in two separate folders(i.e. JList1 shows list of files in Folder A and JList2 shows list of files in Folder B). Also there is a button for selection.

I need to program the button in such a way that only one Item is selected i.e. if I select an Item in JList1 then only that Item gets selected, not any Item in JList2 and vice-versa.

Its something to do with focus methods but I don't know how. I've searched the web, but search-results show item selection in one JList (not two JLists in the same panel).

Sample Codes would be appreciated.

Roshin
  • 26
  • 3

1 Answers1

1

PanelBrowser is an example that uses ListSelectionModel.SINGLE_SELECTION to preclude multiple selection.

Addendum: How do I determine that the currently selected Item is of JList1?

You can use a ListSelectionListener, as shown in the example cited above and How to Write a List Selection Listener. Also consider Action, shown here.

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • BrowsePanel is a great program. But I didn't meant ListSelectionModel.SINGLE_SELECTION. I mean am looking for a method related to focus(i.e. JList1 is currently focused if I select an Item of that list). How do I determine that the currently selected Item is of JList1 ? – Roshin Sep 29 '13 at 16:03
  • I've elaborated above. – trashgod Sep 29 '13 at 16:49