Java Reference
In-Depth Information
add(removeButton,
new GridBagConstraints(1, 4, 1, 2, 0, .25, GridBagConstraints.CENTER,
GridBagConstraints.NONE, new Insets(0,5,0,5), 0, 0));
removeButton.addActionListener(new RemoveListener());
destLabel = new JLabel(DEFAULT_DEST_CHOICE_LABEL);
destListModel = new SortedListModel();
destList = new JList(destListModel);
add(destLabel,
new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.CENTER,
GridBagConstraints.NONE, EMPTY_INSETS, 0, 0));
add(new JScrollPane(destList),
new GridBagConstraints(2, 1, 1, 5, .5, 1.0, GridBagConstraints.CENTER,
GridBagConstraints.BOTH, EMPTY_INSETS, 0, 0));
}
private class AddListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object selected[] = sourceList.getSelectedValues();
addDestinationElements(selected);
clearSourceSelected();
}
}
private class RemoveListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object selected[] = destList.getSelectedValues();
addSourceElements(selected);
clearDestinationSelected();
}
}
public static void main(String args[]) {
Runnable runner = new Runnable() {
public void run() {
JFrame frame = new JFrame("Dual List Box Tester");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DualListBox dual = new DualListBox();
dual.addSourceElements(
new String[] {"One", "Two", "Three"});
dual.addSourceElements(
new String[] {"Four", "Five", "Six"});
dual.addSourceElements(
new String[] {"Seven", "Eight", "Nine"});
dual.addSourceElements(
new String[] {"Ten", "Eleven", "Twelve"});
dual.addSourceElements(
new String[] {"Thirteen", "Fourteen", "Fifteen"});
Search WWH ::




Custom Search