pablosotol

111

Aug 19th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. import java.awt.FlowLayout;
  2. import java.awt.event.ActionListener;
  3. import java.awt.event.ActionEvent;
  4. import javax.swing.JFrame;
  5. import javax.swing.JList;
  6. import javax.swing.JButton;
  7. import javax.swing.JScrollPane;
  8. import javax.swing.ListSelectionModel;
  9.  
  10.  
  11.  
  12. public class JListMultiple extends JFrame {
  13.      
  14.        private JList listaColores;
  15.        private JList listaCopia;
  16.        private JButton botonCopiar;
  17.        private final String nombreColores[]={"Negro","Azul","Verde","Rojo","Celeste","Amarillo"};
  18.        
  19.        public JListMultiple(){
  20.               setLayout(new FlowLayout());
  21.               listaColores=new JList(nombreColores);
  22.               listaColores.setVisibleRowCount(5);
  23.               listaColores.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
  24.               add(new JScrollPane(listaColores));
  25.               botonCopiar=new JButton("Copiar");
  26.               botonCopiar.addActionListener(new Accion());
  27.               add(botonCopiar);
  28.               listaCopia=new JList();
  29.               listaCopia.setVisibleRowCount(5);
  30.               listaCopia.setFixedCellWidth(100);
  31.               listaCopia.setFixedCellHeight(15);
  32.               listaCopia.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
  33.               add(new JScrollPane(listaCopia));
  34.               setVisible(true);
  35.               setSize(350,140);
  36.               setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  37.            
  38.        }
  39.        
  40.        private class Accion implements ActionListener{
  41.                
  42.                @Override
  43.                public void actionPerformed(ActionEvent e){
  44.                       listaCopia.setListData(listaColores.getSelectedValues());
  45.                }
  46.        }
  47.    
  48.     public static void main(String[] args) {
  49.            JListMultiple jm=new JListMultiple();
  50.     }
  51.    
  52. }
Advertisement
Add Comment
Please, Sign In to add comment