Example usage for javax.swing JTextArea setText

List of usage examples for javax.swing JTextArea setText

Introduction

In this page you can find the example usage for javax.swing JTextArea setText.

Prototype

@BeanProperty(bound = false, description = "the text of this component")
public void setText(String t) 

Source Link

Document

Sets the text of this TextComponent to the specified text.

Usage

From source file:org.tinymediamanager.ui.dialogs.BugReportDialog.java

/**
 * Instantiates a new feedback dialog./*from  www  . j a  va2 s  . com*/
 */
public BugReportDialog() {
    super(BUNDLE.getString("BugReport"), "bugReportdialog");
    getContentPane().setLayout(new BorderLayout(0, 0));

    JPanel panelContent = new JPanel();
    getContentPane().add(panelContent, BorderLayout.CENTER);
    panelContent.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.DEFAULT_COLSPEC, FormSpecs.LABEL_COMPONENT_GAP_COLSPEC,
                    ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC,
                    ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.UNRELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"),
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, RowSpec.decode("default:grow"),
                    FormSpecs.UNRELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.UNRELATED_GAP_ROWSPEC,
                    RowSpec.decode("default:grow"), FormSpecs.UNRELATED_GAP_ROWSPEC, }));

    final JTextArea taDescription = new JTextArea();
    taDescription.setOpaque(false);
    taDescription.setWrapStyleWord(true);
    taDescription.setLineWrap(true);
    taDescription.setEditable(false);
    taDescription.setText(BUNDLE.getString("BugReport.description")); //$NON-NLS-1$
    panelContent.add(taDescription, "2, 2, 6, 1, fill, fill");

    final JButton btnSaveLogs = new JButton(BUNDLE.getString("BugReport.createlogs")); //$NON-NLS-1$
    btnSaveLogs.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // open the log download window
            try {
                Path file = TmmUIHelper.saveFile(BUNDLE.getString("BugReport.savelogs"), "tmm_logs.zip", //$NON-NLS-1$
                        new FileNameExtensionFilter("Zip files", ".zip"));
                if (file != null) {
                    writeLogsFile(file.toFile());
                }
            } catch (Exception ex) {
                LOGGER.error("Could not write logs.zip: " + ex.getMessage());
            }
        }
    });

    final JLabel lblStep1 = new JLabel(BUNDLE.getString("BugReport.step1")); //$NON-NLS-1$
    panelContent.add(lblStep1, "2, 4, default, top");

    final JTextArea taStep1 = new JTextArea();
    taStep1.setText(BUNDLE.getString("BugReport.step1.description")); //$NON-NLS-1$
    taStep1.setOpaque(false);
    taStep1.setEditable(false);
    panelContent.add(taStep1, "5, 4, fill, fill");
    panelContent.add(btnSaveLogs, "7, 4");

    final JButton btnCreateIssue = new JButton(BUNDLE.getString("BugReport.craeteissue")); //$NON-NLS-1$
    btnCreateIssue.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // create the url for github
            String baseUrl = "https://github.com/tinyMediaManager/tinyMediaManager/issues/new?body=";
            String params = "Version: " + ReleaseInfo.getRealVersion();
            params += "\nBuild: " + ReleaseInfo.getRealBuildDate();
            params += "\nOS: " + System.getProperty("os.name") + " " + System.getProperty("os.version");
            params += "\nJDK: " + System.getProperty("java.version") + " " + System.getProperty("os.arch") + " "
                    + System.getProperty("java.vendor");
            params += "\n\n__What is the actual behaviour?__\n\n";
            params += "\n\n__What is the expected behaviour?__\n\n";
            params += "\n\n__Steps to reproduce:__\n\n";
            params += "\n\n__Additional__\nHave you attached the logfile from the day it happened?";

            String url = "";
            try {
                url = baseUrl + URLEncoder.encode(params, "UTF-8");
                TmmUIHelper.browseUrl(url);
            } catch (Exception e1) {
                LOGGER.error("FAQ", e1);
                MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, url, "message.erroropenurl",
                        new String[] { ":", e1.getLocalizedMessage() }));
            }
        }
    });

    final JLabel lblStep2 = new JLabel(BUNDLE.getString("BugReport.step2")); //$NON-NLS-1$
    panelContent.add(lblStep2, "2, 6, default, top");

    final JTextArea taStep2 = new JTextArea();
    taStep2.setOpaque(false);
    taStep2.setEditable(false);
    taStep2.setText(BUNDLE.getString("BugReport.step2.description")); //$NON-NLS-1$
    panelContent.add(taStep2, "5, 6, fill, fill");
    panelContent.add(btnCreateIssue, "7, 6");

    final JLabel lblHintIcon = new JLabel(IconManager.HINT);
    panelContent.add(lblHintIcon, "3, 8");

    final JLabel lblHint = new JLabel(BUNDLE.getString("BugReport.languagehint")); //$NON-NLS-1$
    panelContent.add(lblHint, "5, 8");

    JPanel panelButtons = new JPanel();

    getContentPane().add(panelButtons, BorderLayout.SOUTH);

    JButton btnClose = new JButton(BUNDLE.getString("Button.close")); //$NON-NLS-1$
    btnClose.setIcon(IconManager.CANCEL);
    btnClose.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setVisible(false);
        }
    });
    panelButtons.setLayout(new FormLayout(
            new ColumnSpec[] { ColumnSpec.decode("default:grow"), FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("25px"),
                    FormSpecs.RELATED_GAP_ROWSPEC, }));
    panelButtons.add(btnClose, "2, 2");
}

From source file:org.tinymediamanager.ui.dialogs.RegisterDonatorVersionDialog.java

public RegisterDonatorVersionDialog() {
    super(BUNDLE.getString("tmm.registerdonator"), "registerDonator"); //$NON-NLS-1$
    setBounds(166, 5, 400, 300);/*from   www  .jav a2  s. c  o  m*/
    boolean isDonator = Globals.isDonator();
    Properties props = null;
    if (isDonator) {
        props = License.decrypt();
    }

    {
        JPanel panelContent = new JPanel();
        getContentPane().add(panelContent, BorderLayout.CENTER);
        panelContent.setLayout(new FormLayout(
                new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                        FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("250px:grow"),
                        FormFactory.RELATED_GAP_COLSPEC, },
                new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"),
                        FormFactory.PARAGRAPH_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.UNRELATED_GAP_ROWSPEC, }));

        {
            JTextArea textArea = new JTextArea();
            textArea.setOpaque(false);
            textArea.setLineWrap(true);
            textArea.setWrapStyleWord(true);
            textArea.setEditable(false);
            panelContent.add(textArea, "2, 2, 3, 1, default, center");
            if (isDonator) {
                textArea.setText(BUNDLE.getString("tmm.registerdonator.thanks")); //$NON-NLS-1$
            } else {
                textArea.setText(BUNDLE.getString("tmm.registerdonator.hint")); //$NON-NLS-1$
            }
        }
        {
            JLabel lblName = new JLabel(BUNDLE.getString("tmm.registerdonator.name")); //$NON-NLS-1$
            panelContent.add(lblName, "2, 4, right, default");
            tfName = new JTextField("");
            lblName.setLabelFor(tfName);
            panelContent.add(tfName, "4, 4, fill, default");
            tfName.setColumns(10);
            if (isDonator) {
                tfName.setText(props.getProperty("user"));
                tfName.setEnabled(false);
            }
        }
        {
            JLabel lblEmailAddress = new JLabel(BUNDLE.getString("tmm.registerdonator.email")); //$NON-NLS-1$
            panelContent.add(lblEmailAddress, "2, 6, right, default");
            tfEmailAddress = new JTextField("");
            lblEmailAddress.setLabelFor(tfEmailAddress);
            panelContent.add(tfEmailAddress, "4, 6, fill, default");
            tfEmailAddress.setColumns(10);
            if (isDonator) {
                tfEmailAddress.setText(props.getProperty("email"));
                tfEmailAddress.setEnabled(false);
            }
        }
    }
    {
        JPanel panelButtons = new JPanel();
        panelButtons.setBorder(new EmptyBorder(4, 4, 4, 4));
        getContentPane().add(panelButtons, BorderLayout.SOUTH);
        EqualsLayout layout = new EqualsLayout(5);
        layout.setMinWidth(100);
        panelButtons.setLayout(layout);
        {
            JButton btnRegister = new JButton(BUNDLE.getString("Button.register")); //$NON-NLS-1$
            btnRegister.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    try {
                        LOGGER.debug("registering for donator version: ", tfEmailAddress.getText());
                        Properties p = new Properties();
                        p.setProperty("user", tfName.getText());
                        p.setProperty("email", tfEmailAddress.getText());
                        p.setProperty("generated", String.valueOf(new Date().getTime()));
                        p.setProperty("uuid", FileUtils.readFileToString(new File("tmm.uuid")));

                        // get encrypted string and write tmm.lic
                        if (License.encrypt(p) && License.isValid()) {
                            JOptionPane.showMessageDialog(RegisterDonatorVersionDialog.this,
                                    BUNDLE.getString("tmm.registerdonator.success")); //$NON-NLS-1$
                            setVisible(false);
                        } else {
                            JOptionPane.showMessageDialog(RegisterDonatorVersionDialog.this,
                                    BUNDLE.getString("tmm.registerdonator.error")); //$NON-NLS-1$
                        }
                    } catch (Exception ex) {
                        LOGGER.error("Error registering donator version: " + ex.getMessage());
                    }
                    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                }
            });
            if (isDonator) {
                btnRegister.setEnabled(false);
            }
            panelButtons.add(btnRegister);
        }
        {
            JButton btnClose = new JButton(BUNDLE.getString("Button.close")); //$NON-NLS-1$
            btnClose.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent arg0) {
                    setVisible(false);
                }
            });
            panelButtons.add(btnClose);
        }
    }
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            tfName.requestFocus();
        }
    });
}

From source file:org.transitime.gui.ExceptionPanel.java

/**
 * Initialize the contents of the frame.
 *///w w  w  .  jav  a 2s .c om
private void initialize() {
    JPanel middlePanel = new JPanel();
    middlePanel.setBorder(new TitledBorder(new EtchedBorder(), "Error Starting TransitimeQuickStart"));

    // create the middle panel components

    JTextArea display = new JTextArea(35, 90);
    display.setEditable(false); // set textArea non-editable
    JScrollPane scroll = new JScrollPane(display);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    //Add Textarea in to middle panel
    middlePanel.add(scroll);

    JFrame frame = new JFrame();
    frame.add(middlePanel);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    String stackTrace = ExceptionUtils.getStackTrace(ex);
    display.setText(message + "\n" + ex.toString() + "\n" + stackTrace);
}

From source file:org.ut.biolab.medsavant.client.variant.ImportVariantsWizard.java

private AbstractWizardPage getAddTagsPage() {
    //setup page//from  w w w . j  av  a  2  s .  com
    final DefaultWizardPage page = new DefaultWizardPage("Add Tags") {
        @Override
        public void setupWizardButtons() {
            fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH);
            fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK);
            fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT);
        }
    };

    page.addText("Variants can be filtered by tag value in the Filter section.");
    page.addText("Add tags for this set of variants:");

    final String[] patternExamples = { "<Tag Name>", "Sequencer", "Sequencer Version", "Variant Caller",
            "Variant Caller Version", "Technician" };

    locationField = new JComboBox(patternExamples);
    locationField.setEditable(true);

    final JPanel tagContainer = new JPanel();
    ViewUtil.applyVerticalBoxLayout(tagContainer);

    final JTextField valueField = new JTextField();

    final String startingValue = "<Value>";
    valueField.setText(startingValue);

    final JTextArea ta = new JTextArea();
    ta.setRows(10);
    ta.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    ta.setEditable(false);

    JLabel button = ViewUtil.createIconButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.ADD));
    button.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {

            if (locationField.getSelectedItem().toString().isEmpty()) {
                DialogUtils.displayError("Tag cannot be empty");
                locationField.requestFocus();
                return;
            } else if (locationField.getSelectedItem().toString().equals(patternExamples[0])) {
                DialogUtils.displayError("Enter a valid tag name");
                locationField.requestFocus();
                return;
            }

            if (valueField.getText().toString().isEmpty()) {
                DialogUtils.displayError("Value cannot be empty");
                valueField.requestFocus();
                return;
            } else if (valueField.getText().equals(startingValue)) {
                DialogUtils.displayError("Enter a valid value");
                valueField.requestFocus();
                return;
            }

            VariantTag tag = new VariantTag((String) locationField.getSelectedItem(), valueField.getText());

            variantTags.add(tag);
            ta.append(tag.toString() + "\n");
            valueField.setText("");
        }
    });

    JPanel container2 = new JPanel();
    ViewUtil.clear(container2);
    ViewUtil.applyHorizontalBoxLayout(container2);
    container2.add(locationField);
    container2.add(ViewUtil.clear(new JLabel(" = ")));
    container2.add(valueField);
    container2.add(button);

    page.addComponent(container2);
    locationField.setToolTipText("Current display range");

    locationField.setPreferredSize(LOCATION_SIZE);
    locationField.setMinimumSize(LOCATION_SIZE);

    valueField.setPreferredSize(LOCATION_SIZE);
    valueField.setMinimumSize(LOCATION_SIZE);

    page.addComponent(tagContainer);

    page.addComponent(new JScrollPane(ta));

    JButton clear = new JButton("Clear");
    clear.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            variantTags.clear();
            ta.setText("");
            addDefaultTags(variantTags, ta);
        }
    });

    addDefaultTags(variantTags, ta);

    page.addComponent(ViewUtil.alignRight(clear));

    return page;

}

From source file:org.wandora.application.gui.topicpanels.ProcessingTopicPanel.java

private void showRichErrorDialog(String msg) {
    final JTextArea area = new JTextArea();
    area.setFont(errorMessageFont);//from   www  .  j  a va  2 s. c  o m
    //area.setPreferredSize(new Dimension(520, 180));
    area.setEditable(false);
    area.setText(msg);

    // Make the JOptionPane resizable using the HierarchyListener
    area.addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            Window window = SwingUtilities.getWindowAncestor(area);
            if (window instanceof Dialog) {
                Dialog dialog = (Dialog) window;
                if (!dialog.isResizable()) {
                    dialog.setResizable(true);
                }
            }
        }
    });

    JScrollPane scroller = new JScrollPane(area);
    scroller.setPreferredSize(new Dimension(520, 180));
    JOptionPane.showMessageDialog(Wandora.getWandora(), scroller, "Errors", JOptionPane.PLAIN_MESSAGE);
}

From source file:pcgen.gui2.dialog.AboutDialog.java

/**
 * Build up a scrollable list of monkeys, given the monkey names.
 * @param monkeys The names of the monkeys
 * @return A JScrollPane to display the monkeys.
 *//*from  w  w w .ja  v a2  s. c  om*/
private JScrollPane buildMonkeyList(String monkeys) {
    JTextArea textArea = new JTextArea();
    JScrollPane scroller = new JScrollPane();

    textArea.setWrapStyleWord(true);
    textArea.setLineWrap(true);
    textArea.setEditable(false);
    textArea.setText(monkeys);
    scroller.setViewportView(textArea);
    textArea.setCaretPosition(0);

    return scroller;
}

From source file:pcgen.gui2.dialog.AboutDialog.java

/**
 * Construct the includes panel. This panel shows details
 * and licencing statrements about any libraries distributed
 * with PCGen.//w w  w  . j a  va 2  s.  c  o m
 *
 * @return The includes panel.
 */
private JPanel buildIncludesPanel() {
    JPanel iPanel = new JPanel();

    JTextArea otherLibrariesField = new JTextArea();

    iPanel.setLayout(new BorderLayout());

    String s = LanguageBundle.getString("in_abt_lib_apache"); //$NON-NLS-1$
    s += LanguageBundle.getString("in_abt_lib_jdom"); //$NON-NLS-1$
    s += LanguageBundle.getString("in_abt_lib_l2f"); //$NON-NLS-1$
    otherLibrariesField.setText(s);
    otherLibrariesField.setWrapStyleWord(true);
    otherLibrariesField.setLineWrap(true);
    otherLibrariesField.setEditable(false);
    otherLibrariesField.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));

    iPanel.add(otherLibrariesField, BorderLayout.CENTER);

    return iPanel;
}

From source file:pcgen.gui2.dialog.AboutDialog.java

/**
 * Construct the awards panel. This panel shows each award
 * the pcgen project has been awarded/*from  w  w w . j av a2  s.  c  o  m*/
 *
 * @return The awards panel.
 */
private JPanel buildAwardsPanel() {
    JScrollPane sp = new JScrollPane();
    JPanel panel = new JPanel();

    JPanel aPanel = new JPanel();
    aPanel.setLayout(new GridBoxLayout(2, 2));
    aPanel.setBackground(Color.WHITE);
    Icon goldIcon = Icons.createImageIcon("gold200x200-2005.gif");
    if (goldIcon != null) {
        JLabel e2005 = new JLabel(goldIcon);
        aPanel.add(e2005);

        JTextArea title = new JTextArea();
        title.setLineWrap(true);
        title.setWrapStyleWord(true);
        title.setEditable(false);
        title.setText(LanguageBundle.getString("in_abt_awards_2005_ennie"));
        aPanel.add(title);
    }

    Icon bronzeIcon = Icons.createImageIcon("bronze200x200-2003.gif");
    if (bronzeIcon != null) {
        JLabel e2003 = new JLabel(bronzeIcon);
        aPanel.add(e2003);

        JTextArea title = new JTextArea();
        title.setLineWrap(true);
        title.setWrapStyleWord(true);
        title.setEditable(false);
        title.setText(LanguageBundle.getString("in_abt_awards_2003_ennie"));
        aPanel.add(title);
    }

    sp.setViewportView(aPanel);
    panel.add(sp, BorderLayout.CENTER);
    return panel;
}

From source file:pcgen.gui2.dialog.AboutDialog.java

/**
 * Construct the license panel. This panel shows the full
 * text of the license under which PCGen is distributed.
 *
 * @return The license panel./*from  www.j a  va  2 s.c o m*/
 */
private JPanel buildLicensePanel() {
    JPanel lPanel = new JPanel();

    JScrollPane license = new JScrollPane();
    JTextArea lgplArea = new JTextArea();

    lPanel.setLayout(new BorderLayout());

    lgplArea.setEditable(false);

    InputStream lgpl = ClassLoader.getSystemResourceAsStream("LICENSE"); //$NON-NLS-1$

    if (lgpl != null) {
        try {
            lgplArea.read(new InputStreamReader(lgpl), "LICENSE"); //$NON-NLS-1$
        } catch (IOException ioe) {
            lgplArea.setText(LanguageBundle.getString("in_abt_license_read_err1")); //$NON-NLS-1$
        }
    } else {
        lgplArea.setText(LanguageBundle.getString("in_abt_license_read_err2")); //$NON-NLS-1$
    }

    license.setViewportView(lgplArea);
    lPanel.add(license, BorderLayout.CENTER);

    return lPanel;
}

From source file:phenoviewer.ReNameJFrame.java

private void showError(Vector error) {
    // show the error massage
    JTextArea textArea = new JTextArea(10, 40);
    textArea.setEditable(false);//from   ww  w.  j ava  2  s .c o  m
    String m = "";
    for (int i = 0; i < error.size(); i++) {
        m += error.get(i) + "\n";
    }

    textArea.setText(m);
    textArea.setForeground(Color.RED);
    JScrollPane scrollPane = new JScrollPane(textArea);
    JOptionPane.showMessageDialog(null, scrollPane, "Error Message", JOptionPane.ERROR_MESSAGE);

    return;
}