Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.FlowLayout;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JFrame;
- import javax.swing.JButton;
- import javax.swing.JScrollPane;
- import javax.swing.JList;
- import javax.swing.ListSelectionModel;
- class MultiGUI extends JFrame {
- private JList leftList;
- private JList rightList;
- private JButton moveButton;
- private String foods[ ] = {"fish", "beacon", "chicken", "ham", "egg", "milk", "apple"};
- public static void main(String args[ ]) {
- MultiGUI gui = new MultiGUI();
- gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- gui.setSize(350, 150);
- gui.setVisible(true);
- }
- MultiGUI() {
- super("super duper mover");
- setLayout(new FlowLayout());
- leftList = new JList(foods);
- leftList.setVisibleRowCount(5);
- leftList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
- add(new JScrollPane(leftList));
- moveButton = new JButton("move -->");
- moveButton.addActionListener(
- new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- rightList.setListData(leftList.getSelectedValues());
- }
- }
- );
- add(moveButton);
- rightList = new JList();
- rightList.setVisibleRowCount(5);
- rightList.setFixedCellHeight(15);
- rightList.setFixedCellWidth(100);
- add(new JScrollPane(rightList));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement