{filelink=3527}
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 JListTransfert extends JFrame
{
final JList list_src; // Liste Source
final JList list_dest; // Liste destinataire
// JListTransfert constructor
public JListTransfert()
{
JButton btn_copy;
final String programs[] = {"C"
,"C++"
,"C#"
,"Java"
,"Perl"
,"PHP"
,"Python"};
setLayout( new FlowLayout() );
list_src = new JList( programs );
list_src.setVisibleRowCount( 5 );
list_src.setSelectionMode(
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
add( new JScrollPane( list_src ) ); // add list with scrollpane
btn_copy = new JButton( "Envoyer >>>" ); // create copy button
btn_copy.addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent event )
{
// Envoyer les valeurs sélectionnée dans list_dest
list_dest.setListData( list_src.getSelectedValues() );
}
}
);
add( btn_copy );
list_dest = new JList();
list_dest.setVisibleRowCount( 5 );
list_dest.setFixedCellWidth( 100 );
list_dest.setFixedCellHeight( 15 );
list_dest.setSelectionMode(
ListSelectionModel.SINGLE_INTERVAL_SELECTION );
setSize(300,250);
setTitle("Exemple de JList");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add( new JScrollPane( list_dest ) );
}
public static void main (String[] args)
{
new JListTransfert().setVisible(true);
}
}