All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.com.generationjava.swing.JListOperatorButton Maven / Gradle / Ivy

The newest version!
package com.generationjava.swing;

import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.tree.*;
import javax.swing.event.*;

/**
 * A button which cuts an item from one JList and transfers it 
 * to another JList.
 *
 * @author [email protected]
 * @date   2000-09-05
 */
public class JListOperatorButton extends JButton {

    // no idea of a clipboard.
    // copy and cut require two JList's, delete just the one.
    public static Object COPY    = new Object();
    public static Object CUT     = new Object();
    public static Object DELETE  = new Object();

    private JList  sourceList  = null;
    private JList  targetList    = null;
    private Object opType     = null;

    static public void main(String[] strs) {
        JFrame frame = new JFrame("Test JListOperatorCut");
        Object[] objs = new Object[] { "Apple", "Banana", "Zebra" };
        DefaultListModel model = new DefaultListModel();
        for(int i=0;i0;i--) {
            Object element = sourceListModel.getElementAt(selec[i-1]);
            if(!opType.equals(COPY)) {
                sourceListModel.removeElementAt(selec[i-1]);
            }
            if(!opType.equals(DELETE)) {
                targetListModel.addElement(element);
            }
        }
        sourceList.revalidate();
        targetList.revalidate();
    }

    public JList getSourceList() {
        return sourceList;
    }

    public void setSourceList(JList list) {
        sourceList = list;
    }

    public JList getTargetList() {
        return targetList;
    }

    public void setTargetList(JList list) {
        targetList = list;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy