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.JList;
- import javax.swing.JButton;
- import javax.swing.JScrollPane;
- import javax.swing.ListSelectionModel;
- public class JListMultiple extends JFrame {
- private JList listaColores;
- private JList listaCopia;
- private JButton botonCopiar;
- private final String nombreColores[]={"Negro","Azul","Verde","Rojo","Celeste","Amarillo"};
- public JListMultiple(){
- setLayout(new FlowLayout());
- listaColores=new JList(nombreColores);
- listaColores.setVisibleRowCount(5);
- listaColores.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
- add(new JScrollPane(listaColores));
- botonCopiar=new JButton("Copiar");
- botonCopiar.addActionListener(new Accion());
- add(botonCopiar);
- listaCopia=new JList();
- listaCopia.setVisibleRowCount(5);
- listaCopia.setFixedCellWidth(100);
- listaCopia.setFixedCellHeight(15);
- listaCopia.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
- add(new JScrollPane(listaCopia));
- setVisible(true);
- setSize(350,140);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- private class Accion implements ActionListener{
- @Override
- public void actionPerformed(ActionEvent e){
- listaCopia.setListData(listaColores.getSelectedValues());
- }
- }
- public static void main(String[] args) {
- JListMultiple jm=new JListMultiple();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment