Advertisement
Kvarz

JList - moving list of item program(1part) try1

Nov 3rd, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. import javax.swing.*;
  5. //import javax.swing.event.*;
  6.  
  7.  
  8. public class Gui extends JFrame {
  9.     private static final long serialVersionUID = 2L;
  10.    
  11.         private JList<String> rightlist;
  12.         private JList<String>  leftlist;
  13.         private JList<String>  newlist;
  14.         private JButton movebutton;
  15.        
  16.         private static String[] foods = {"bread", "ice-cream", "pastry", "pancakes", "tea","jam","honey"};
  17.        
  18.         public Gui(){
  19.             super("Movelist program");
  20.             setLayout(new FlowLayout());
  21.            
  22.             leftlist = new JList<String>(foods);
  23.             leftlist.setVisibleRowCount(4);
  24.             leftlist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
  25.             add(new JScrollPane(leftlist));
  26.             //get a list of strings with some other method of JList<> that is not deprecated
  27.             newlist = new JList<String>(leftlist.getSelectedValues());
  28.            
  29.             movebutton = new JButton("Move -->");
  30.             movebutton.addActionListener(
  31.                     new ActionListener(){
  32.                         public void actionPerformed(ActionEvent event){
  33.                             //rightlist.setListData(leftlist.getSelectedValues());
  34.                             rightlist.setListData(leftlist.newlist);
  35.                         }
  36.                     }
  37.             );
  38.            
  39.             add(movebutton);
  40.            
  41.             rightlist = new JList<String>();
  42.             rightlist.setVisibleRowCount(5);
  43.             rightlist.setFixedCellWidth(70);
  44.             rightlist.setFixedCellHeight(15);
  45.             rightlist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
  46.             add(new JScrollPane(rightlist));
  47.            
  48.         }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement