Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.event.*;
- public class Gui extends JFrame{
- // Variables
- private JList leftlist;
- private JList rightlist;
- private JButton movebutton;
- private static String[] foods = {"bacon", "wings", "ham", "beef", "more bacon"};
- // Constructor
- public Gui(){
- super("JFrame's title");
- setLayout(new FlowLayout());
- leftlist = new JList(foods);
- leftlist.setVisibleRowCount(3); // 3 items seen by default
- leftlist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
- add(new JScrollPane(leftlist));
- // add(leftlist);
- movebutton = new JButton("Move --->");
- movebutton.addActionListener(
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent event) {
- rightlist.setListData(leftlist.getSelectedValues());
- }
- }
- );
- add(movebutton);
- rightlist = new JList();
- rightlist.setVisibleRowCount(3);
- rightlist.setFixedCellHeight(15);
- rightlist.setFixedCellWidth(100);
- rightlist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
- add(new JScrollPane(rightlist));
- }
- // Main Function
- public static void main(String[] args){
- Gui gui = new Gui();
- gui.setDefaultCloseOperation(EXIT_ON_CLOSE);
- gui.setSize(600, 600);
- gui.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement