4

Currently I'm having a container to list all the (JPanel) panels in a scroll pane. The function that I'm trying to accomplish is trying to reorder the panels. For example: moving the 2nd panel to the first, then moving the 3rd panel to the last spot. Currently I'm thinking using the Containers Index and moving them in the data layer.

What is a good way to represent the moving in the GUI form?

The only idea I have is putting up and down arrows in on the panel. Which doesn't look so pretty, and very messy when you have like 100+ panels.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
The JAVA Noob
  • 367
  • 4
  • 8
  • 21
  • How about Drag-and-Drop? – GreyBeardedGeek May 03 '12 at 02:59
  • Hi Grey, i looked up the DnD libraries, but I'm not too confident. I've been looking up examples where you can drag and drop panels. But most examples are Drag and Drop Texts. – The JAVA Noob May 03 '12 at 04:13
  • Is the updation of the `JPanel` happening too often ? if not, you can use an `ArrayList` to store `JPanel`s then and add them again to your `JFrame` when you know whom to move and where :-) – nIcE cOw May 03 '12 at 05:53

1 Answers1

3

I see two general approaches to reorder a collection of JPanel instances in response to an event:

  • Change the actual order of the panels in the container by removing them all, altering the order, validating the enclosing container and repainting; this example shows the basic idea for JLabel instances.

  • Change the apparent order of the panels in the view using the flyweight pattern and a tabular renderer; this example shows the basic idea using CellRendererPane.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045