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() 

Source Link

Document

Constructs a new TextArea.

Usage

From source file:view.App.java

private void initGUI() {
    try {/*from  w w w  . j av a 2s  . c om*/
        {
            jPanel1 = new JPanel();
            BorderLayout jPanel1Layout = new BorderLayout();
            jPanel1.setLayout(jPanel1Layout);
            getContentPane().add(jPanel1, BorderLayout.CENTER);
            jPanel1.setPreferredSize(new java.awt.Dimension(901, 398));
            {
                jPanel2 = new JPanel();
                BoxLayout jPanel2Layout = new BoxLayout(jPanel2, javax.swing.BoxLayout.Y_AXIS);
                jPanel2.setLayout(jPanel2Layout);
                jPanel1.add(jPanel2, BorderLayout.WEST);
                jPanel2.setPreferredSize(new java.awt.Dimension(292, 446));
                {
                    jPanel5 = new JPanel();
                    jPanel2.add(jPanel5);
                    jPanel5.setPreferredSize(new java.awt.Dimension(292, 109));
                    {
                        {
                            jTextArea1 = new JTextArea();
                            jTextArea1.setWrapStyleWord(true);
                            jTextArea1.setLineWrap(true);
                            DefaultCaret caret = (DefaultCaret) jTextArea1.getCaret();
                            caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

                            jTextArea1.addFocusListener(new FocusAdapter() {
                                public void focusGained(FocusEvent evt) {

                                    if (jTable1.getModel().getRowCount() == 0 && !jButton1.isEnabled()) {
                                        jButton1.setEnabled(true);
                                        jTextArea1.setText("");
                                    }

                                }
                            });
                            JScrollPane sp = new JScrollPane();
                            sp.setPreferredSize(new java.awt.Dimension(281, 97));
                            sp.setViewportView(jTextArea1);

                            jPanel5.add(sp, BorderLayout.CENTER);
                        }
                    }

                }
                {
                    jPanel4 = new JPanel();
                    jPanel2.add(jPanel4);
                    FlowLayout jPanel4Layout = new FlowLayout();
                    jPanel4Layout.setAlignment(FlowLayout.RIGHT);
                    jPanel4.setPreferredSize(new java.awt.Dimension(292, 45));
                    jPanel4.setSize(102, 51);
                    jPanel4.setLayout(jPanel4Layout);
                    {
                        jButton1 = new JButton();
                        jPanel4.add(jButton1);
                        jButton1.setText("Get Quotes");
                        jButton1.setSize(100, 50);
                        jButton1.setPreferredSize(new java.awt.Dimension(100, 26));
                        jButton1.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                //   
                                String tickerStr = jTextArea1.getText();
                                if (tickerStr.equals("") || tickerStr.equals(null)
                                        || tickerStr.equals(" ")) {
                                    jTextArea1.setText(" ");
                                    return;
                                }
                                StringTokenizer tokenizer = new StringTokenizer(tickerStr, " ");
                                String[] tickers = new String[tokenizer.countTokens()];
                                int i = 0;
                                while (tokenizer.hasMoreTokens()) {
                                    tickers[i] = tokenizer.nextToken();
                                    i++;
                                }
                                try {
                                    Controller.getQuotes(tickers);
                                } catch (CloneNotSupportedException e) {
                                    JOptionPane.showMessageDialog(jPanel1, "   ");
                                }
                                jButton1.setEnabled(false);
                            }
                        });
                    }
                }
                {
                    jPanel6 = new JPanel();
                    BorderLayout jPanel6Layout = new BorderLayout();
                    jPanel6.setLayout(jPanel6Layout);
                    jPanel2.add(jPanel6);
                    {
                        jScrollPane1 = new JScrollPane();
                        jPanel6.add(jScrollPane1, BorderLayout.CENTER);
                        jScrollPane1.setPreferredSize(new java.awt.Dimension(292, 341));
                        {
                            TableModel jTable1Model = new DefaultTableModel(null,
                                    new String[] { "", "MA Value", "", "MA Value" });
                            jTable1 = new JTable();

                            jScrollPane1.setViewportView(jTable1);
                            jTable1.setModel(jTable1Model);
                            jTable1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);

                        }
                    }
                }
            }
            {
                jPanel3 = new JPanel();
                BorderLayout jPanel3Layout = new BorderLayout();
                jPanel3.setLayout(jPanel3Layout);
                jPanel1.add(jPanel3, BorderLayout.CENTER);
                {
                    //                  chart = ChartFactory.createLineChart(" ", "dates", "correlation ratio", null, 
                    //                        PlotOrientation.VERTICAL, true, true, false);
                    //                  ChartPanel chartPanel = new ChartPanel(chart);
                    //                  chartPanel.setPreferredSize( new java.awt.Dimension( 560 , 367 ) );
                    //                  jPanel3.add(chartPanel);
                }
                {

                }
            }
        }
        this.setSize(966, 531);
        {
            jMenuBar1 = new JMenuBar();
            setJMenuBar(jMenuBar1);
            {
                jMenu3 = new JMenu();
                jMenuBar1.add(jMenu3);
                jMenu3.setText("File");
                {
                    //                  newFileMenuItem = new JMenuItem();
                    //                  jMenu3.add(newFileMenuItem);
                    //                  newFileMenuItem.setText("New");
                    //                  newFileMenuItem.addActionListener(new ActionListener() {
                    //                     public void actionPerformed(ActionEvent evt) {
                    ////                        jTextArea1.setText("");
                    ////                        DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
                    ////                        model.setRowCount(0);
                    ////                        Controller.clearPortfolio();
                    //                     }
                    //                  });
                }
                {
                    jSeparator2 = new JSeparator();
                    jMenu3.add(jSeparator2);
                }
                {
                    exitMenuItem = new JMenuItem();
                    jMenu3.add(exitMenuItem);
                    exitMenuItem.setText("Exit");
                    exitMenuItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            int action = JOptionPane.showConfirmDialog(jPanel1,
                                    "     ?", "Confirm Exit",
                                    JOptionPane.OK_CANCEL_OPTION);

                            if (action == JOptionPane.OK_OPTION)
                                System.exit(0);

                        }
                    });
                }
            }
            {
                jMenu4 = new JMenu();
                jMenuBar1.add(jMenu4);
                jMenu4.setText("Edit");
                {
                    cutMenuItem = new JMenuItem();
                    jMenu4.add(cutMenuItem);
                    cutMenuItem.setText("Cut");
                    cutMenuItem.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            String txt = jTextArea1.getText();
                            StringSelection selection = new StringSelection(txt);
                            Clipboard clp = Toolkit.getDefaultToolkit().getSystemClipboard();
                            clp.setContents(selection, null);
                            jTextArea1.setText("");

                        }
                    });
                }
                {
                    copyMenuItem = new JMenuItem();
                    jMenu4.add(copyMenuItem);
                    copyMenuItem.setText("Copy");
                    copyMenuItem.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent arg0) {
                            String txt = jTextArea1.getText();
                            StringSelection selection = new StringSelection(txt);
                            Clipboard clp = Toolkit.getDefaultToolkit().getSystemClipboard();
                            clp.setContents(selection, null);

                        }
                    });
                }
                {
                    pasteMenuItem = new JMenuItem();
                    jMenu4.add(pasteMenuItem);
                    pasteMenuItem.setText("Paste");
                    pasteMenuItem.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            Clipboard clp = Toolkit.getDefaultToolkit().getSystemClipboard();
                            try {
                                String data = (String) clp.getData(DataFlavor.stringFlavor);
                                jTextArea1.setText(data);
                            } catch (UnsupportedFlavorException e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                            } catch (IOException e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                            }
                        }
                    });
                }
            }
            {
                jMenu5 = new JMenu();
                jMenuBar1.add(jMenu5);
                jMenu5.setText("Help");
                {
                    helpMenuItem = new JMenuItem();
                    jMenu5.add(helpMenuItem);
                    helpMenuItem.setText("About");
                    helpMenuItem.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent arg0) {
                            JOptionPane.showMessageDialog(jPanel1,
                                    "    .    r.zhumagulov@gmail.com",
                                    "About", JOptionPane.PLAIN_MESSAGE);

                        }
                    });
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:gtu._work.ui.RetryByPassUI.java

private void initGUI() {
    try {//from w  w w  . jav  a2 s  .c o  m
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                FlowLayout jPanel1Layout = new FlowLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("?", null, jPanel1, null);
                {
                    DefaultComboBoxModel countryComboBoxModel = new DefaultComboBoxModel();
                    for (CountyEnum e : CountyEnum.values()) {
                        countryComboBoxModel.addElement(e.countyLabel);
                    }
                    countryComboBox = new JComboBox();
                    jPanel1.add(countryComboBox);
                    countryComboBox.setModel(countryComboBoxModel);
                }
                {
                    ComboBoxModel passRetryComboBoxModel = new DefaultComboBoxModel(
                            new String[] { "byPass", "reTry", "status" });
                    passRetryComboBox = new JComboBox();
                    jPanel1.add(passRetryComboBox);
                    passRetryComboBox.setModel(passRetryComboBoxModel);
                }
                {
                    sendBtn = new JButton();
                    jPanel1.add(sendBtn);
                    sendBtn.setText("\u9001\u51fa");
                    sendBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            //TODO add your code for sendBtn.actionPerformed
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    readMessageId();
                                }
                            }).start();
                        }
                    });
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("messageId", null, jPanel2, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel2.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(604, 375));
                    {
                        messageIdArea = new JTextArea();
                        jScrollPane1.setViewportView(messageIdArea);
                    }
                }
            }
            {
                jPanel3 = new JPanel();
                BorderLayout jPanel3Layout = new BorderLayout();
                jPanel3.setLayout(jPanel3Layout);
                jTabbedPane1.addTab("?", null, jPanel3, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel3.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(604, 375));
                    {
                        executeLogArea = new JTextArea();
                        jScrollPane2.setViewportView(executeLogArea);
                    }
                }
            }
        }
        pack();
        this.setSize(617, 429);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}

From source file:gtu._work.etc.EnglishAdd.java

private void initGUI() {
    try {//from  w  w  w  .  ja  v  a 2 s . com
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        this.setPreferredSize(new java.awt.Dimension(400, 211));
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            jTabbedPane1.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent evt) {
                    if (jTabbedPane1.getSelectedIndex() == 2) {
                        // XXX
                    }
                }
            });
            {
                jPanel1 = new JPanel();
                FlowLayout jPanel1Layout = new FlowLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("add", null, jPanel1, null);
                jPanel1.setPreferredSize(new java.awt.Dimension(387, 233));
                {
                    showwordText = new JTextField();
                    jPanel1.add(showwordText);
                    showwordText.setPreferredSize(new java.awt.Dimension(271, 23));
                    showwordText.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent evt) {
                            if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                                scanWord();
                            }
                        }
                    });
                    showwordText.addFocusListener(new FocusAdapter() {
                        public void focusLost(FocusEvent evt) {
                            scanWord();
                        }
                    });
                }
                {
                    netChkBox = new JCheckBox();
                    jPanel1.add(netChkBox);
                    netChkBox.setSelected(true);
                }
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel1.add(jScrollPane2);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(364, 80));
                    {
                        showChineseArea = new JTextArea();
                        jScrollPane2.setViewportView(showChineseArea);
                        showChineseArea.setPreferredSize(new java.awt.Dimension(364, 80));
                    }
                }
                {
                    setFileBtn = new JButton();
                    jPanel1.add(setFileBtn);
                    setFileBtn.setText("set file");
                    setFileBtn.setPreferredSize(new java.awt.Dimension(261, 30));
                    setFileBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JCommonUtil._jFileChooser_selectFileOnly();
                            if (file == null) {
                                JCommonUtil._jOptionPane_showMessageDialog_error("?!");
                                return;
                            }
                            currentFile = file;

                            StringBuffer sb = new StringBuffer();
                            try {
                                BufferedReader reader = new BufferedReader(
                                        new InputStreamReader(new FileInputStream(currentFile), "BIG5"));
                                for (String line = null; (line = reader.readLine()) != null;) {
                                    sb.append(line + "\r\n");
                                }
                                reader.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            wordTextArea.setText(sb.toString());
                        }
                    });
                }
            }
            {
                jPanel3 = new JPanel();
                BorderLayout jPanel3Layout = new BorderLayout();
                jPanel3.setLayout(jPanel3Layout);
                jTabbedPane1.addTab("word", null, jPanel3, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel3.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(387, 224));
                    {
                        wordTextArea = new JTextArea();
                        jScrollPane1.setViewportView(wordTextArea);
                    }
                }
            }
        }

        setDefaultSave();

        pack();
        this.setSize(400, 211);
    } catch (Exception e) {
        // add your error handling code here
        e.printStackTrace();
    }
}

From source file:FocusEventDemo.java

public FocusEventDemo() {
    super(new GridBagLayout());
    GridBagLayout gridbag = (GridBagLayout) getLayout();
    GridBagConstraints c = new GridBagConstraints();

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0; //Make column as wide as possible.
    JTextField textField = new JTextField("A TextField");
    textField.setMargin(new Insets(0, 2, 0, 2));
    textField.addFocusListener(this);
    gridbag.setConstraints(textField, c);
    add(textField);/*from   ww  w. ja  va  2 s.  com*/

    c.weightx = 0.1; //Widen every other column a bit, when possible.
    c.fill = GridBagConstraints.NONE;
    JLabel label = new JLabel("A Label");
    label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    label.addFocusListener(this);
    gridbag.setConstraints(label, c);
    add(label);

    String comboPrefix = "ComboBox Item #";
    final int numItems = 15;
    Vector vector = new Vector(numItems);
    for (int i = 0; i < numItems; i++) {
        vector.addElement(comboPrefix + i);
    }
    JComboBox comboBox = new JComboBox(vector);
    comboBox.addFocusListener(this);
    gridbag.setConstraints(comboBox, c);
    add(comboBox);

    c.gridwidth = GridBagConstraints.REMAINDER;
    JButton button = new JButton("A Button");
    button.addFocusListener(this);
    gridbag.setConstraints(button, c);
    add(button);

    c.weightx = 0.0;
    c.weighty = 0.1;
    c.fill = GridBagConstraints.BOTH;
    String listPrefix = "List Item #";
    Vector listVector = new Vector(numItems);
    for (int i = 0; i < numItems; i++) {
        listVector.addElement(listPrefix + i);
    }
    JList list = new JList(listVector);
    list.setSelectedIndex(1); //It's easier to see the focus change
    //if an item is selected.
    list.addFocusListener(this);
    JScrollPane listScrollPane = new JScrollPane(list);
    //We want to prevent the list's scroll bars
    //from getting the focus - even with the keyboard.
    //Note that in general we prefer setRequestFocusable
    //over setFocusable for reasons of accessibility,
    //but this is to work around bug #4866958.
    listScrollPane.getVerticalScrollBar().setFocusable(false);
    listScrollPane.getHorizontalScrollBar().setFocusable(false);
    gridbag.setConstraints(listScrollPane, c);
    add(listScrollPane);

    c.weighty = 1.0; //Make this row as tall as possible.
    c.gridheight = GridBagConstraints.REMAINDER;
    //Set up the area that reports focus-gained and focus-lost events.
    display = new JTextArea();
    display.setEditable(false);
    //The method setRequestFocusEnabled prevents a
    //component from being clickable, but it can still
    //get the focus through the keyboard - this ensures
    //user accessibility.
    display.setRequestFocusEnabled(false);
    display.addFocusListener(this);
    JScrollPane displayScrollPane = new JScrollPane(display);

    //Work around for bug #4866958.
    displayScrollPane.getHorizontalScrollBar().setFocusable(false);
    displayScrollPane.getVerticalScrollBar().setFocusable(false);
    gridbag.setConstraints(displayScrollPane, c);
    add(displayScrollPane);

    setPreferredSize(new Dimension(450, 450));
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:com.sec.ose.osi.ui.dialog.progress.JDlgProgress.java

/**
 * This method initializes jTextAreaMessage   
 *    //from  w w  w  . j a v a  2s .c  om
 * @return javax.swing.JTextArea   
 */
private JTextArea getJTextAreaMessage() {
    if (jTextAreaMessage == null) {
        jTextAreaMessage = new JTextArea();
        jTextAreaMessage.setEditable(false);
        jTextAreaMessage.setBackground(new Color(238, 238, 238));
        jTextAreaMessage.setText("Executing");
        jTextAreaMessage.setRows(4);
        jTextAreaMessage.setPreferredSize(new Dimension(300, 18));
        jTextAreaMessage.setDisabledTextColor(Color.BLACK);
        jTextAreaMessage.setEnabled(false);
    }
    return jTextAreaMessage;
}

From source file:com.loy.MainFrame.java

@SuppressWarnings("rawtypes")
public void init() {

    String src = "ee.png";
    try {//from  ww  w  .j av  a 2s .co m
        ClassPathResource classPathResource = new ClassPathResource(src);
        image = ImageIO.read(classPathResource.getURL());
        this.setIconImage(image);
    } catch (IOException e) {
    }

    menu = new JMenu("LOG CONSOLE");
    this.jmenuBar = new JMenuBar();
    this.jmenuBar.add(menu);

    panel = new JPanel(new BorderLayout());
    this.add(panel);

    ClassPathResource classPathResource = new ClassPathResource("application.yml");
    Yaml yaml = new Yaml();
    Map result = null;
    try {
        result = (Map) yaml.load(classPathResource.getInputStream());
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    String platformStr = result.get("platform").toString();
    String version = result.get("version").toString();
    String jvmOption = result.get("jvmOption").toString();
    @SuppressWarnings("unchecked")
    List<String> projects = (List<String>) result.get("projects");
    platform = Platform.valueOf(platformStr);
    final Runtime runtime = Runtime.getRuntime();
    File pidsForder = new File("./pids");
    if (!pidsForder.exists()) {
        pidsForder.mkdir();
    } else {
        File[] files = pidsForder.listFiles();
        if (files != null) {
            for (File f : files) {
                f.deleteOnExit();
                String pidStr = f.getName();
                try {
                    Long pid = new Long(pidStr);
                    if (Processes.isProcessRunning(platform, pid)) {
                        if (Platform.Windows == platform) {
                            Processes.tryKillProcess(null, platform, new NullProcessor(), pid);
                        } else {
                            Processes.killProcess(null, platform, new NullProcessor(), pid);
                        }

                    }
                } catch (Exception ex) {
                }
            }
        }
    }

    File currentForder = new File("");
    String rootPath = currentForder.getAbsolutePath();
    rootPath = rootPath.replace(File.separator + "build" + File.separator + "libs", "");
    rootPath = rootPath.replace(File.separator + "e-example-ms-start-w", "");

    for (String value : projects) {
        String path = value;
        String[] values = value.split("/");
        value = values[values.length - 1];
        String appName = value;
        value = rootPath + "/" + path + "/build/libs/" + value + "-" + version + ".jar";

        JMenuItem menuItem = new JMenuItem(appName);
        JTextArea textArea = new JTextArea();
        textArea.setVisible(true);
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        textArea.setAutoscrolls(true);
        JScrollPane scorll = new JScrollPane(textArea);
        this.textSreaMap.put(appName, scorll);
        EComposite ecomposite = new EComposite();
        ecomposite.setCommand(value);
        ecomposite.setTextArea(textArea);
        composites.put(appName, ecomposite);
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Collection<JScrollPane> values = textSreaMap.values();
                for (JScrollPane t : values) {
                    t.setVisible(false);
                }
                String actions = e.getActionCommand();
                JScrollPane textArea = textSreaMap.get(actions);
                if (textArea != null) {
                    textArea.setVisible(true);
                    panel.removeAll();
                    panel.add(textArea);
                    panel.repaint();
                    panel.validate();
                    self.repaint();
                    self.validate();
                }
            }
        });
        menu.add(menuItem);
    }

    new Thread(new Runnable() {
        @Override
        public void run() {
            int size = composites.keySet().size();
            int index = 1;
            for (String appName : composites.keySet()) {
                EComposite composite = composites.get(appName);
                try {

                    Process process = runtime.exec(
                            "java " + jvmOption + " -Dfile.encoding=UTF-8 -jar " + composite.getCommand());
                    Long pid = Processes.processId(process);
                    pids.add(pid);
                    File pidsFile = new File("./pids", pid.toString());
                    pidsFile.createNewFile();

                    new WriteLogThread(process.getInputStream(), composite.getTextArea()).start();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                synchronized (lock) {
                    try {
                        if (index < size) {
                            lock.wait();
                        } else {
                            index++;
                        }

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }).start();

}