Example usage for javax.swing JTextField setDragEnabled

List of usage examples for javax.swing JTextField setDragEnabled

Introduction

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

Prototype

@BeanProperty(bound = false, description = "determines whether automatic drag handling is enabled")
public void setDragEnabled(boolean b) 

Source Link

Document

Turns on or off automatic drag handling.

Usage

From source file:DnDBetweenJTextAreaAndJTextFieldDemo.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Drag and Drop Demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new JPanel());
    JTextField textField = new JTextField(25);
    textField.setText("www.java2s.com");
    frame.add(textField);/*from  ww  w  .j a  v  a  2 s .c o m*/

    JTextArea textArea = new JTextArea(4, 25);
    textArea.setText("Demonstrating\ndrag and drop");
    frame.getContentPane().add(new JScrollPane(textArea));
    textArea.setDragEnabled(true);
    textField.setDragEnabled(true);
    frame.pack();
    frame.setVisible(true);

}

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);/*  ww w  .j  av a 2  s  .  com*/

    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:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField field1 = new JTextField("Life's a drag", 20);
    JTextField field2 = new JTextField("and then you drop", 20);
    field1.setDragEnabled(true);
    field2.setDragEnabled(true);// w w  w.j a v  a2  s  .  c  o m
    Container content = getContentPane();

    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    content.add(field1);
    content.add(field2);

    pack();
}

From source file:DragDropText.java

public DragDropText() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField field1 = new JTextField("Life's a drag", 20);
    JTextField field2 = new JTextField("and then you drop", 20);
    field1.setDragEnabled(true);
    field2.setDragEnabled(true);//from w  w  w.  ja  v  a 2 s  . c  om
    Container content = getContentPane();

    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    content.add(field1);
    content.add(field2);

    pack();
}

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);/*from   w  w  w.j a  va 2s.  c  o  m*/
    textField.setDragEnabled(true);
    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: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);// www  .j  a  va  2 s .co m
    textField.setDragEnabled(true);
    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 ww  w.  j  a  v  a2s  .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:DragColorTextFieldDemo.java

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

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

    JColorChooser chooser = new JColorChooser();
    chooser.setDragEnabled(true);//  www  .j a  v  a 2 s  .  c  om
    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);
}