/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* ListBsp.java
*
* Created on 21.04.2010, 12:58:16
*/
package teste;
import javax.swing.DefaultListModel;
import javax.swing.JList;
public class ListBsp extends javax.swing.JFrame {
/** Creates new form ListBsp */
public ListBsp() {
initComponents();
// add some test data
DefaultListModel model = (DefaultListModel)jListA.getModel();
model.addElement("Wort1");
model.addElement("Wort2");
model.addElement("Wort3");
model.addElement("Wort4");
model.addElement("Wort5");
model.addElement("Wort6");
model.addElement("Wort7");
model.addElement("Wort8");
model.addElement("Wort9");
model.addElement("Wort10");
}
private void removeWord(Object o){
DefaultListModel model = (DefaultListModel)jListA.getModel();
System.out.println("Removing "+o);
model.removeElement(o);
}
private void moveObjectToList(Object o, JList source, JList target){
System.out.println("Removing "+o);
((DefaultListModel)source.getModel()).removeElement(o);
System.out.println("Adding to "+o);
((DefaultListModel)target.getModel()).addElement(o);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jListA = new javax.swing.JList();
jButtonRemoveA = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
jListB = new javax.swing.JList();
jButtonRemoveB = new javax.swing.JButton();
jButtonMoveB = new javax.swing.JButton();
jButtonMoveA = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jListA.setModel(new DefaultListModel());
jScrollPane1.setViewportView(jListA);
jButtonRemoveA.setText("remove");
jButtonRemoveA.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonRemoveAActionPerformed(evt);
}
});
jListB.setModel(new DefaultListModel());
jScrollPane2.setViewportView(jListB);
jButtonRemoveB.setText("remove");
jButtonRemoveB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonRemoveBActionPerformed(evt);
}
});
jButtonMoveB.setText(">>");
jButtonMoveB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonMoveBActionPerformed(evt);
}
});
jButtonMoveA.setText("<<");
jButtonMoveA.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonMoveAActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jButtonRemoveA, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButtonMoveB)
.addComponent(jButtonMoveA))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jButtonRemoveB, 0, 0, Short.MAX_VALUE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE))
.addContainerGap(10, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(65, 65, 65)
.addComponent(jButtonMoveB)
.addGap(18, 18, 18)
.addComponent(jButtonMoveA))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButtonRemoveA)
.addComponent(jButtonRemoveB))))))
.addContainerGap())
);
pack();
}// </editor-fold>
private void jButtonRemoveAActionPerformed(java.awt.event.ActionEvent evt) {
Object[] selectValues = jListA.getSelectedValues();
for(Object o : selectValues){
removeWord(o);
}
}
private void jButtonRemoveBActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButtonMoveAActionPerformed(java.awt.event.ActionEvent evt) {
Object[] selectValues = jListB.getSelectedValues();
for(Object o : selectValues){
moveObjectToList(o,jListB,jListA);
}
}
private void jButtonMoveBActionPerformed(java.awt.event.ActionEvent evt) {
Object[] selectValues = jListA.getSelectedValues();
for(Object o : selectValues){
moveObjectToList(o,jListA,jListB);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ListBsp().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButtonMoveA;
private javax.swing.JButton jButtonMoveB;
private javax.swing.JButton jButtonRemoveA;
private javax.swing.JButton jButtonRemoveB;
private javax.swing.JList jListA;
private javax.swing.JList jListB;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
// End of variables declaration
}