Example usage for javax.swing JTextArea JTextArea

List of usage examples for javax.swing JTextArea JTextArea

Introduction

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

Prototype

public JTextArea(String text, int rows, int columns) 

Source Link

Document

Constructs a new TextArea with the specified text and number of rows and columns.

Usage

From source file:FlowLayoutBehaviour.java

public FlowLayoutBehaviour() {
    super();/*  w w w . ja  va 2  s  .c om*/
    Container pane = getContentPane();
    pane.setLayout(new FlowLayout(FlowLayout.LEFT));
    pane.add(new JLabel("This is a test"));
    pane.add(new JButton("of a FlowLayout"));
    pane.add(new JTextField(30));
    pane.add(new JTextArea("This is a JTextArea", 3, 10));
    pane.add(new JLabel("This is a FlowLayout test with a long string"));
}

From source file:fll.scheduler.ChooseChallengeDescriptor.java

private void initComponents() {
    getContentPane().setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.weightx = 1;//from  w  ww. j av  a  2s  .  c o  m
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.BOTH;
    final JTextArea instructions = new JTextArea(
            "Choose a challenge description from the drop down list OR choose a file containing your custom challenge description.",
            3, 40);
    instructions.setEditable(false);
    instructions.setWrapStyleWord(true);
    instructions.setLineWrap(true);
    getContentPane().add(instructions, gbc);

    gbc = new GridBagConstraints();
    mCombo = new JComboBox<DescriptionInfo>();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    getContentPane().add(mCombo, gbc);
    mCombo.setRenderer(new DescriptionInfoRenderer());
    mCombo.setEditable(false);
    final List<DescriptionInfo> descriptions = DescriptionInfo.getAllKnownChallengeDescriptionInfo();
    for (final DescriptionInfo info : descriptions) {
        mCombo.addItem(info);
    }

    mFileField = new JLabel();
    gbc = new GridBagConstraints();
    gbc.weightx = 1;
    getContentPane().add(mFileField, gbc);

    final JButton chooseButton = new JButton("Choose File");
    gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    getContentPane().add(chooseButton, gbc);
    chooseButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent ae) {
            mFileField.setText(null);

            final JFileChooser fileChooser = new JFileChooser();
            final FileFilter filter = new BasicFileFilter("FLL Description (xml)", new String[] { "xml" });
            fileChooser.setFileFilter(filter);

            final int returnVal = fileChooser.showOpenDialog(ChooseChallengeDescriptor.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                final File selectedFile = fileChooser.getSelectedFile();
                mFileField.setText(selectedFile.getAbsolutePath());
            }
        }
    });

    final Box buttonPanel = new Box(BoxLayout.X_AXIS);
    gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    getContentPane().add(buttonPanel, gbc);

    buttonPanel.add(Box.createHorizontalGlue());
    final JButton ok = new JButton("Ok");
    buttonPanel.add(ok);
    ok.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent ae) {

            // use the selected description if nothing is entered in the file box
            final DescriptionInfo descriptionInfo = mCombo.getItemAt(mCombo.getSelectedIndex());
            if (null != descriptionInfo) {
                mSelected = descriptionInfo.getURL();
            }

            final String text = mFileField.getText();
            if (!StringUtils.isEmpty(text)) {
                final File file = new File(text);
                if (file.exists()) {
                    try {
                        mSelected = file.toURI().toURL();
                    } catch (final MalformedURLException e) {
                        throw new FLLInternalException("Can't turn file into URL?", e);
                    }
                }
            }

            setVisible(false);
        }
    });

    final JButton cancel = new JButton("Cancel");
    buttonPanel.add(cancel);
    cancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent ae) {
            mSelected = null;
            setVisible(false);
        }
    });

    pack();
}

From source file:FocusConceptsDemo.java

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

    b1 = new JButton("JButton");
    b2 = new JButton("JButton");
    b3 = new JButton("JButton");
    b4 = new JButton("JButton");
    JPanel buttonPanel = new JPanel(new GridLayout(1, 1));
    buttonPanel.add(b1);/*from w ww.  j  a  va  2 s .co  m*/
    buttonPanel.add(b2);
    buttonPanel.add(b3);
    buttonPanel.add(b4);

    text1 = new JTextArea("JTextArea", 15, 40);
    JPanel textAreaPanel = new JPanel(new BorderLayout());
    textAreaPanel.add(text1, BorderLayout.CENTER);

    t1 = new JTextField("JTextField");
    t2 = new JTextField("JTextField");
    t3 = new JTextField("JTextField");
    t4 = new JTextField("JTextField");
    JPanel textFieldPanel = new JPanel(new GridLayout(1, 1));
    textFieldPanel.add(t1);
    textFieldPanel.add(t2);
    textFieldPanel.add(t3);
    textFieldPanel.add(t4);

    add(buttonPanel, BorderLayout.PAGE_START);
    add(textAreaPanel, BorderLayout.CENTER);
    add(textFieldPanel, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:fungus.MycoNodeFrame.java

public MycoNodeFrame(MycoNode node) {
    this.node = node;
    this.setTitle("Node " + node.getID());

    graph = JungGraphObserver.getGraph();

    Container contentPane = getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
    JPanel labelPane = new JPanel();
    labelPane.setLayout(new GridLayout(7, 2));
    JPanel neighborPane = new JPanel();
    neighborPane.setLayout(new BoxLayout(neighborPane, BoxLayout.PAGE_AXIS));
    JPanel logPane = new JPanel();
    logPane.setLayout(new BoxLayout(logPane, BoxLayout.PAGE_AXIS));
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));

    loggingTextArea = new JTextArea("", 25, 100);
    loggingTextArea.setLineWrap(true);/*from  w w w . j  a v  a  2  s  . c  o  m*/
    loggingTextArea.setEditable(false);
    handler = new MycoNodeLogHandler(node, loggingTextArea);
    handler.addChangeListener(this);
    JScrollPane logScrollPane = new JScrollPane(loggingTextArea);
    logScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    logPane.add(logScrollPane);

    contentPane.add(labelPane);
    //contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    contentPane.add(neighborPane);
    //contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    contentPane.add(logPane);
    contentPane.add(buttonPane);

    data = node.getHyphaData();
    link = node.getHyphaLink();
    mycocast = node.getMycoCast();

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    stateLabel = new JLabel();
    typeLabel = new JLabel();
    queueLengthLabel = new JLabel();
    sameLabel = new JLabel();
    differentLabel = new JLabel();
    maxCapacityLabel = new JLabel();
    idealImmobileLabel = new JLabel();
    idealHyphaeLabel = new JLabel();
    idealBiomassLabel = new JLabel();
    degreeLabel = new JLabel();
    hyphaDegreeLabel = new JLabel();
    biomassDegreeLabel = new JLabel();
    hyphaUtilizationLabel = new JLabel();
    biomassUtilizationLabel = new JLabel();
    capacityUtilizationLabel = new JLabel();

    labelPane.add(new JLabel("state"));
    labelPane.add(stateLabel);
    labelPane.add(new JLabel("type"));
    labelPane.add(typeLabel);
    labelPane.add(new JLabel("queue"));
    labelPane.add(queueLengthLabel);
    labelPane.add(new JLabel(""));
    labelPane.add(new JLabel(""));
    labelPane.add(new JLabel("same"));
    labelPane.add(sameLabel);
    labelPane.add(new JLabel("different"));
    labelPane.add(differentLabel);
    //labelPane.add(new JLabel("immobile"));
    //labelPane.add(idealImmobileLabel);
    labelPane.add(new JLabel(""));
    labelPane.add(new JLabel("actual"));
    labelPane.add(new JLabel("ideal"));
    labelPane.add(new JLabel("utilization"));
    labelPane.add(new JLabel("hyphae"));
    labelPane.add(hyphaDegreeLabel);
    labelPane.add(idealHyphaeLabel);
    labelPane.add(hyphaUtilizationLabel);
    labelPane.add(new JLabel("biomass"));
    labelPane.add(biomassDegreeLabel);
    labelPane.add(idealBiomassLabel);
    labelPane.add(biomassUtilizationLabel);
    labelPane.add(new JLabel("capacity"));
    labelPane.add(degreeLabel);
    labelPane.add(maxCapacityLabel);
    labelPane.add(capacityUtilizationLabel);

    neighborListControl = new JList();
    neighborListControl.setLayoutOrientation(JList.VERTICAL_WRAP);
    neighborListControl.setVisibleRowCount(-1);

    neighborListScroller = new JScrollPane(neighborListControl);
    neighborListScroller.setPreferredSize(new Dimension(250, 150));
    neighborListScroller.setMinimumSize(new Dimension(250, 150));

    neighborPane.add(neighborListScroller);

    JButton updateButton = new JButton("Refresh");
    ActionListener updater = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            refreshData();
        }
    };
    updateButton.addActionListener(updater);

    JButton closeButton = new JButton("Close");
    ActionListener closer = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            closeFrame();
        }
    };
    closeButton.addActionListener(closer);

    buttonPane.add(Box.createHorizontalGlue());
    buttonPane.add(updateButton);
    buttonPane.add(Box.createRigidArea(new Dimension(5, 0)));
    buttonPane.add(closeButton);

    refreshData();

    JungGraphObserver.addChangeListener(this);

    this.pack();
    this.setVisible(true);
}

From source file:CutAndPasteDemo.java

public CutAndPasteDemo() {
    super("Cut And Paste Demonstration");

    clipboard = getToolkit().getSystemClipboard();

    GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font font = new Font("LucidaSans", Font.PLAIN, 15);
    textArea1 = new JTextArea(davidMessage + andyMessage, 5, 25);
    textArea2 = new JTextArea("<Paste text here>", 5, 25);
    textArea1.setFont(font);/*from   ww w .  java2s.  co  m*/
    textArea2.setFont(font);

    JPanel jPanel = new JPanel();
    JMenuBar jMenuBar = new JMenuBar();
    JMenuItem cutItem = new JMenuItem("Cut");
    JMenuItem pasteItem = new JMenuItem("Paste");
    JMenu jMenu = new JMenu("Edit");
    jMenu.add(cutItem);
    jMenu.add(pasteItem);

    cutItem.addActionListener(new CutActionListener());
    pasteItem.addActionListener(new PasteActionListener());

    jMenuBar.add(jMenu);
    jPanel.add(jMenuBar);

    jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
    jPanel.add(textArea1);
    jPanel.add(Box.createRigidArea(new Dimension(0, 10)));
    jPanel.add(textArea2);

    getContentPane().add(jPanel, BorderLayout.CENTER);
}

From source file:sanger.team16.gui.genevar.eqtl.snp.CisEQTLSNPPane.java

public void setSubmitSNPPanel(SelectedIndex selectedIndex) {
    BaseJPane panel = new BaseJPane("Query SNPs");

    // ------------------ Panel p0 (start) ------------------ //
    BaseJPane p0 = new BaseJPane();

    p0.add(new JLabel("1. Select a study: "));
    cbStudy = new JComboBox(this.ui.getStudies("E"));
    cbStudy.setSelectedIndex(selectedIndex.studyIndex);
    cbStudy.addActionListener(this);
    p0.add(cbStudy);/*from www  . j  a  v  a2 s  .  c  o m*/

    p0.add(new JLabel(" "));

    p0.setBaseSpringBoxTrailing();
    panel.add(p0);
    // ------------------ Panel p0 (end) ------------------ //

    panel.add(new JLabel(""));

    // ------------------ Panel p1 (start) ------------------ //
    BaseJPane p1 = new BaseJPane();
    p1.add(new JLabel("2. Choose a reference: "));

    this.study = (Study) cbStudy.getSelectedItem();
    cbReference = new JComboBox(
            this.ui.getReferences(study.getGenotypeAssemblyId(), study.getExpressionPlatformId()));
    cbReference.setSelectedIndex(selectedIndex.referencesIndex);
    cbReference.addActionListener(this);
    p1.add(cbReference);

    p1.add(new JLabel(" "));
    p1.setBaseSpringBoxTrailing();
    panel.add(p1);
    // ------------------ Panel p1 (end) ------------------ // 

    panel.add(new JLabel(""));

    /* ----------------- Panel p3 (start) ----------------- */
    BaseJPane p3 = new BaseJPane();
    p3.add(new JLabel("3. Enter rs ID(s): "));

    taSNP = new JTextArea(selectedIndex.textArea1, 6, 1);
    p3.add(new JScrollPane(taSNP));

    p3.add(new JLabel(" "));
    p3.setBaseSpringBoxTrailing();
    panel.add(p3);
    /* ----------------- Panel p3 (end) ----------------- */

    //        

    /* ----------------- Panel p4 (start) ----------------- */
    BaseJPane p4 = new BaseJPane();
    p4.add(new JLabel("    or read from a text file with list of SNPs: "));

    tfSNPFile = new BaseJTextField(5, true, true);
    tfSNPFile.setText("");
    p4.add(tfSNPFile);

    bSNPFile = new JButton("Browse...");
    bSNPFile.addActionListener(this);
    p4.add(bSNPFile);

    p4.add(new JLabel(" "));
    p4.setBaseSpringBoxTrailing();
    panel.add(p4);
    /* ----------------- Panel p4 (end) ----------------- */

    panel.add(new JLabel(""));
    panel.add(new JLabel(""));

    panel.add(this.setMatchedFeaturePanel());

    panel.setBaseSpringGrid(1);
    this.add(panel);
}

From source file:sanger.team16.gui.genevar.mqtl.snp.CisMQTLSNPPane.java

public void setSubmitSNPPanel(SelectedIndex selectedIndex) {
    BaseJPane panel = new BaseJPane("Query SNPs");

    // ------------------ Panel p0 (start) ------------------ //
    BaseJPane p0 = new BaseJPane();

    p0.add(new JLabel("1. Select a study: "));
    cbStudy = new JComboBox(this.ui.getStudies("M"));
    cbStudy.setSelectedIndex(selectedIndex.studyIndex);
    cbStudy.addActionListener(this);
    p0.add(cbStudy);/*from   ww  w  . j a  v a2s.  co  m*/

    p0.add(new JLabel(" "));

    p0.setBaseSpringBoxTrailing();
    panel.add(p0);
    // ------------------ Panel p0 (end) ------------------ //

    panel.add(new JLabel(""));

    // ------------------ Panel p1 (start) ------------------ //
    BaseJPane p1 = new BaseJPane();
    p1.add(new JLabel("2. Choose a reference: "));

    this.study = (Study) cbStudy.getSelectedItem();
    cbReference = new JComboBox(
            this.ui.getReferences(study.getGenotypeAssemblyId(), study.getMethylationPlatformId()));
    cbReference.setSelectedIndex(selectedIndex.referencesIndex);
    cbReference.addActionListener(this);
    p1.add(cbReference);

    p1.add(new JLabel(" "));
    p1.setBaseSpringBoxTrailing();
    panel.add(p1);
    // ------------------ Panel p1 (end) ------------------ // 

    panel.add(new JLabel(""));

    /* ----------------- Panel p3 (start) ----------------- */
    BaseJPane p3 = new BaseJPane();
    p3.add(new JLabel("3. Enter rs ID(s): "));

    taSNP = new JTextArea(selectedIndex.textArea1, 6, 1);
    p3.add(new JScrollPane(taSNP));

    p3.add(new JLabel(" "));
    p3.setBaseSpringBoxTrailing();
    panel.add(p3);
    /* ----------------- Panel p3 (end) ----------------- */

    //        

    /* ----------------- Panel p4 (start) ----------------- */
    BaseJPane p4 = new BaseJPane();
    p4.add(new JLabel("    or read from a text file with list of SNPs: "));

    tfSNPFile = new BaseJTextField(5, true, true);
    tfSNPFile.setText("");
    p4.add(tfSNPFile);

    bSNPFile = new JButton("Browse...");
    bSNPFile.addActionListener(this);
    p4.add(bSNPFile);

    p4.add(new JLabel(" "));
    p4.setBaseSpringBoxTrailing();
    panel.add(p4);
    /* ----------------- Panel p4 (end) ----------------- */

    panel.add(new JLabel(""));
    panel.add(new JLabel(""));

    panel.add(this.setMatchedFeaturePanel());

    panel.setBaseSpringGrid(1);
    this.add(panel);
}