Example usage for javax.swing JFileChooser setDragEnabled

List of usage examples for javax.swing JFileChooser setDragEnabled

Introduction

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

Prototype

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

Source Link

Document

Sets the dragEnabled property, which must be true to enable automatic drag handling (the first part of drag and drop) on this component.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFileChooser chooser = new JFileChooser();
    File f = new File(new File("filename.txt").getCanonicalPath());

    chooser.setDragEnabled(true);
    chooser.showDialog(new JFrame(""), null);
    File curFile = chooser.getSelectedFile();
}

From source file:FileTransferHandler.java

/**
 * This class demonstrates the FileTransferHandler by installing it on a
 * JTextArea component and providing a JFileChooser to drag and cut files.
 */// ww  w  .  j  a  v a  2 s. c o  m

public static void main(String[] args) {
    // Here's the text area. Note how we wrap our TransferHandler
    // around the default handler returned by getTransferHandler()
    JTextArea textarea = new JTextArea();
    TransferHandler defaultHandler = textarea.getTransferHandler();
    textarea.setTransferHandler(new FileTransferHandler(defaultHandler));
    // Here's a JFileChooser, with dragging explicitly enabled.
    JFileChooser filechooser = new JFileChooser();
    filechooser.setDragEnabled(true);

    // Display them both in a window
    JFrame f = new JFrame("File Transfer Handler Test");
    f.getContentPane().add(new JScrollPane(textarea), "Center");
    f.getContentPane().add(filechooser, "South");
    f.setSize(400, 600);
    f.setVisible(true);
}

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  w  ww .ja  v  a2  s.  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:org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.java

private String searchForFile() {
    String filePath = null;/*from w ww .j  a va2s  .  c om*/
    JFileChooser fc = new JFileChooser();
    fc.setDragEnabled(false);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    String[] EXTENSION = new String[] { "txt", "idx", "hash", "Hash", "kdb" }; //NON-NLS
    FileNameExtensionFilter filter = new FileNameExtensionFilter(
            NbBundle.getMessage(this.getClass(), "HashDbManager.fileNameExtensionFilter.title"), EXTENSION);
    fc.setFileFilter(filter);
    fc.setMultiSelectionEnabled(false);
    if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        File f = fc.getSelectedFile();
        try {
            filePath = f.getCanonicalPath();
        } catch (IOException ex) {
            Logger.getLogger(HashDbManager.class.getName()).log(Level.WARNING,
                    "Couldn't get selected file path", ex); //NON-NLS
        }
    }
    return filePath;
}