Example usage for javax.swing JTextField setTransferHandler

List of usage examples for javax.swing JTextField setTransferHandler

Introduction

In this page you can find the example usage for javax.swing JTextField setTransferHandler.

Prototype

@BeanProperty(hidden = true, description = "Mechanism for transfer of data to and from the component")
public void setTransferHandler(TransferHandler newHandler) 

Source Link

Document

Sets the TransferHandler , which provides support for transfer of data into and out of this component via cut/copy/paste and drag and drop.

Usage

From source file:DnDDemo2.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new JPanel());

    JTextField textField = new JTextField(25);
    textField.setText("Let's swing higher");
    frame.add(textField);//  w w w .  ja  v a2s. c  o m

    JTextArea textArea = new JTextArea("Demonstrating\ndrag and drop");
    textArea.setForeground(Color.red);
    frame.add(new JScrollPane(textArea));

    textArea.setDragEnabled(true);
    textField.setDragEnabled(true);
    TextColorTransferHandler transferHandler = new TextColorTransferHandler();
    textArea.setTransferHandler(transferHandler);
    textField.setTransferHandler(transferHandler);
    frame.pack();
    frame.setVisible(true);
}

From source file:dnd.TextCutPaste.java

public TextCutPaste() {
    super(new BorderLayout());

    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

    //Create the transfer handler.
    TextTransferHandler th = new TextTransferHandler();

    //Create some text fields.
    JPanel buttonPanel = new JPanel(new GridLayout(3, 1));
    JTextField textField = new JTextField("Cut, copy and paste...", 30);
    textField.setTransferHandler(th);
    textField.setDragEnabled(true);/*ww  w  .  j  av  a  2 s  .c om*/
    buttonPanel.add(textField);
    textField = new JTextField("or drag and drop...", 30);
    textField.setTransferHandler(th);
    textField.setDragEnabled(true);
    buttonPanel.add(textField);
    textField = new JTextField("from any of these text fields.", 30);
    textField.setTransferHandler(th);
    textField.setDragEnabled(true);
    buttonPanel.add(textField);
    add(buttonPanel, BorderLayout.CENTER);
}

From source file:SwingDnDTest.java

public SwingDnDFrame() {
    setTitle("SwingDnDTest");
    JTabbedPane tabbedPane = new JTabbedPane();

    JList list = SampleComponents.list();
    tabbedPane.addTab("List", list);
    JTable table = SampleComponents.table();
    tabbedPane.addTab("Table", table);
    JTree tree = SampleComponents.tree();
    tabbedPane.addTab("Tree", tree);
    JFileChooser fileChooser = new JFileChooser();
    tabbedPane.addTab("File Chooser", fileChooser);
    JColorChooser colorChooser = new JColorChooser();
    tabbedPane.addTab("Color Chooser", colorChooser);

    final JTextArea textArea = new JTextArea(4, 40);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setBorder(new TitledBorder(new EtchedBorder(), "Drag text here"));

    JTextField textField = new JTextField("Drag color here");
    textField.setTransferHandler(new TransferHandler("background"));

    tabbedPane.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            textArea.setText("");
        }//from   www .  java2s.  co m
    });

    tree.setDragEnabled(true);
    table.setDragEnabled(true);
    list.setDragEnabled(true);
    fileChooser.setDragEnabled(true);
    colorChooser.setDragEnabled(true);
    textField.setDragEnabled(true);

    add(tabbedPane, BorderLayout.NORTH);
    add(scrollPane, BorderLayout.CENTER);
    add(textField, BorderLayout.SOUTH);
    pack();
}

From source file:TextCutPaste.java

public TextCutPaste() {
    super(new BorderLayout());

    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

    // Create the transfer handler.
    TextTransferHandler th = new TextTransferHandler();

    // Create some text fields.
    JPanel buttonPanel = new JPanel(new GridLayout(3, 1));
    JTextField textField = new JTextField("Cut, copy and paste...", 30);
    textField.setTransferHandler(th);
    textField.setDragEnabled(true);//w  w w . j  a v  a2s . co m
    buttonPanel.add(textField);
    textField = new JTextField("or drag and drop...", 30);
    textField.setTransferHandler(th);
    textField.setDragEnabled(true);
    buttonPanel.add(textField);
    textField = new JTextField("from any of these text fields.", 30);
    textField.setTransferHandler(th);
    textField.setDragEnabled(true);
    buttonPanel.add(textField);
    add(buttonPanel, BorderLayout.CENTER);
}

From source file:DragColorTextFieldDemo.java

public DragColorTextFieldDemo() {
    super(new BorderLayout());
    JTextField textField;

    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

    JColorChooser chooser = new JColorChooser();
    chooser.setDragEnabled(true);//w w  w  . ja  v  a 2 s. c  o  m
    add(chooser, BorderLayout.PAGE_START);

    //Create the color transfer handler.
    colorHandler = new ColorAndTextTransferHandler();

    //Create some text fields.
    JPanel buttonPanel = new JPanel(new GridLayout(3, 1));
    textField = new JTextField("I can accept color/text and drag text.");
    textField.setTransferHandler(colorHandler);
    textField.setDragEnabled(true);
    buttonPanel.add(textField);
    textField = new JTextField("Me too!");
    textField.setTransferHandler(colorHandler);
    textField.setDragEnabled(true);
    buttonPanel.add(textField);
    textField = new JTextField("Me three!");
    textField.setTransferHandler(colorHandler);
    textField.setDragEnabled(true);
    buttonPanel.add(textField);
    add(buttonPanel, BorderLayout.CENTER);
}