-1

If I have a grid of 9 panels within another panel and I want to be able to click a subpanel and on click, send the content of that panel to a 'selected panel' area, how would I go about this? (Imagine a character select page for a videogame. When a player selects their character, it shows an expanded view of the character in a 'selected' pane)

I'm thinking of mouseListeners for each subpanel and retrieving the clicked component but I don't understand how I can copy that clicked component to a 'selected' area.

JoshM
  • 95
  • 1
  • 2
  • 12

1 Answers1

2

Add your items to a JList or single-colum JTable. Add a ListSelectionListener to your chosen component. Specify ListSelectionModel.SINGLE_SELECTION. In your valueChanged() handler, the ListSelectionEvent will tell you what value was selected. Use that information to fill in the fields of an adjacent panel. A complete example, illustrated below, is seen here.

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thank you so much, your answer was very helpful. My next step though, is to implement a whole panel (with it's own graphics2d inside it) instead of your icons but I don't know how to do this or in which part of your code my panel might fit – JoshM Apr 08 '15 at 20:27
  • I'd suggest tinkering with the example cited; you might want to pose a new question based on any problems you encounter. – trashgod Apr 08 '15 at 21:13