Do 开发者_如何学JAVAyou know what is the name of this layout for Java/Swing? Does the Java library already bring us this or should I do that on my own? If so, could any one of you show some samples?
Here's the sample code for a Dual JList. This is not a primitive Swing construct, but something you can build using Swing.
This is not provided by the Java swing library - you would have to roll your own or find a 3rd-party library.
The commercial JIDE Grids has a DualList
(scroll to page bottom for a screenshot).
Generally it's not easy to create a really solid Swing widget. You don't have to use custom UI for DualList, but it still takes a lot of work to get the MVC and UI (under all current LAFs) all working well.
Currently JIDE DualList doesn't support drag-n-drop between the lists, but they promised to add it soon (you can search their forum for DualList if you're a paying customer).
I think that GridBagLayout is what you are looking for.
Basically you have 3 JPanels: the first and third are the blank panes and the one in the middle contains two JButtons. GridBagLayout will be a good choice here.
You would want to add some ActionListeners to the two buttons in the middle to control the behaviour.
精彩评论