Example usage for javax.swing JScrollPane setTransferHandler

List of usage examples for javax.swing JScrollPane setTransferHandler

Introduction

In this page you can find the example usage for javax.swing JScrollPane 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:org.webcat.plugintester.ui.MainFrameBuilder.java

/**
 * Creates and lays out the Swing components for the window.
 *
 * @param frame the JFrame instance that will contain the components
 *//*www .  j  a v  a 2s  . com*/
private void constructFrame(JFrame frame) {
    GridBagConstraints gridBagConstraints;

    fileChooser = new JFileChooser();
    bottomPanel = new JPanel();
    runButton = new JButton();
    mainPanel = new JPanel();
    JLabel webCatHomeLabel = new JLabel();
    webCatHomeField = new JTextField();
    webCatHomeBrowseButton = new JButton();
    JSeparator jSeparator0 = new JSeparator();
    JLabel submissionLabel = new JLabel();
    submissionField = new JTextField();
    submissionBrowseButton = new JButton();
    JSeparator jSeparator1 = new JSeparator();
    JLabel pluginsLabel = new JLabel();
    JPanel pluginsPanel = new JPanel();
    JScrollPane pluginsScrollPane = new JScrollPane();
    pluginsTable = new JTable();
    pluginAddButton = new JButton();
    pluginRemoveButton = new JButton();
    JSeparator jSeparator2 = new JSeparator();
    JTabbedPane tabPane = new JTabbedPane();
    propertiesPanel = new JPanel();
    JScrollPane propertiesScrollPane = new JScrollPane();
    propertiesEditor = new JEditorPane();
    documentationPanel = new JPanel();
    JScrollPane documentationScrollPane = new JScrollPane();
    documentationEditor = new JEditorPane();

    // File chooser
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    // Bottom panel
    bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 4));

    // Run button
    runButton.setText("Run Plug-ins");
    runButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            runButtonActionPerformed(evt);
        }
    });
    bottomPanel.add(runButton);

    frame.getContentPane().add(bottomPanel, BorderLayout.PAGE_END);

    // Main panel
    mainPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
    mainPanel.setLayout(new GridBagLayout());

    // Web-CAT Home field
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = GridBagConstraints.RELATIVE;
    gridBagConstraints.anchor = GridBagConstraints.LINE_START;
    webCatHomeLabel.setText("Web-CAT Home:");
    mainPanel.add(webCatHomeLabel, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    webCatHomeField.setTransferHandler(new WebCATHomeTransferHandler());
    mainPanel.add(webCatHomeField, gridBagConstraints);

    // Web-CAT Home browse button
    webCatHomeBrowseButton.setText("Browse...");
    webCatHomeBrowseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            webCatHomeBrowseButtonActionPerformed(evt);
        }
    });
    mainPanel.add(webCatHomeBrowseButton, new GridBagConstraints());

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(jSeparator0, gridBagConstraints);

    // Submission field
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = GridBagConstraints.RELATIVE;
    gridBagConstraints.anchor = GridBagConstraints.LINE_START;
    submissionLabel.setText("Submission:");
    mainPanel.add(submissionLabel, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    submissionField.setTransferHandler(new SubmissionTransferHandler());
    mainPanel.add(submissionField, gridBagConstraints);

    // Submission browse button
    submissionBrowseButton.setText("Browse...");
    submissionBrowseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            submissionBrowseButtonActionPerformed(evt);
        }
    });
    mainPanel.add(submissionBrowseButton, new GridBagConstraints());

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(jSeparator1, gridBagConstraints);

    // Plug-ins area
    pluginsLabel.setText("Plug-ins to run:");
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(pluginsLabel, gridBagConstraints);

    pluginsPanel.setPreferredSize(new Dimension(400, 80));
    pluginsPanel.setLayout(new GridBagLayout());

    pluginsModel = new PluginsTableModel();
    pluginsTable.setModel(pluginsModel);
    pluginsTable.setColumnSelectionAllowed(true);
    pluginsTable.getTableHeader().setReorderingAllowed(false);
    pluginsScrollPane.setViewportView(pluginsTable);
    pluginsTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    pluginsTable.getColumnModel().getColumn(0).setResizable(false);
    pluginsScrollPane.setTransferHandler(new PluginsTransferHandler());

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    pluginsPanel.add(pluginsScrollPane, gridBagConstraints);

    pluginAddButton.setText("Add...");
    pluginAddButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pluginAddButtonActionPerformed(evt);
        }
    });
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = GridBagConstraints.PAGE_START;
    pluginsPanel.add(pluginAddButton, gridBagConstraints);

    pluginRemoveButton.setText("Remove");

    pluginRemoveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pluginRemoveButtonActionPerformed(evt);
        }
    });
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = GridBagConstraints.PAGE_START;
    pluginsPanel.add(pluginRemoveButton, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 0.25;
    mainPanel.add(pluginsPanel, gridBagConstraints);
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(jSeparator2, gridBagConstraints);

    tabPane.setPreferredSize(new Dimension(466, 150));

    propertiesPanel.setLayout(new GridBagLayout());

    propertiesEditor.addKeyListener(new KeyAdapter() {
        public void keyTyped(KeyEvent e) {
            propertiesTimer.restart();
        }
    });

    propertiesTimer = new Timer(1000, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateGradingProperties();
        }
    });

    propertiesScrollPane.setViewportView(propertiesEditor);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    propertiesPanel.add(propertiesScrollPane, gridBagConstraints);

    tabPane.addTab("Properties", propertiesPanel);

    documentationPanel.setLayout(new GridBagLayout());

    documentationEditor.setContentType("text/html");
    documentationEditor.setEditable(false);
    documentationScrollPane.setViewportView(documentationEditor);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    documentationPanel.add(documentationScrollPane, gridBagConstraints);

    tabPane.addTab("Documentation", documentationPanel);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.gridheight = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weighty = 1.0;
    mainPanel.add(tabPane, gridBagConstraints);

    frame.getContentPane().add(mainPanel, BorderLayout.CENTER);

    frame.pack();
}