Reorder panels in scroll-pane
java, jpanel, swing, user-interface
Solution
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`.
Problem
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.