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:events.ContainerEventDemo.java

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

    //Initialize an empty list of buttons.
    buttonList = new Vector<JButton>(10, 10);

    //Create all the components.
    addButton = new JButton("Add a button");
    addButton.setActionCommand(ADD);//www  .  j ava  2 s  . c o  m
    addButton.addActionListener(this);

    removeButton = new JButton("Remove a button");
    removeButton.setActionCommand(REMOVE);
    removeButton.addActionListener(this);

    buttonPanel = new JPanel(new GridLayout(1, 1));
    buttonPanel.setPreferredSize(new Dimension(200, 75));
    buttonPanel.addContainerListener(this);

    display = new JTextArea();
    display.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(display);
    scrollPane.setPreferredSize(new Dimension(200, 75));

    clearButton = new JButton("Clear text area");
    clearButton.setActionCommand(CLEAR);
    clearButton.addActionListener(this);

    c.fill = GridBagConstraints.BOTH; //Fill entire cell.
    c.weighty = 1.0; //Button area and message area have equal height.
    c.gridwidth = GridBagConstraints.REMAINDER; //end of row
    gridbag.setConstraints(scrollPane, c);
    add(scrollPane);

    c.weighty = 0.0;
    gridbag.setConstraints(clearButton, c);
    add(clearButton);

    c.weightx = 1.0; //Add/remove buttons have equal width.
    c.gridwidth = 1; //NOT end of row
    gridbag.setConstraints(addButton, c);
    add(addButton);

    c.gridwidth = GridBagConstraints.REMAINDER; //end of row
    gridbag.setConstraints(removeButton, c);
    add(removeButton);

    c.weighty = 1.0; //Button area and message area have equal height.
    gridbag.setConstraints(buttonPanel, c);
    add(buttonPanel);

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

From source file:hu.bme.mit.sette.snippetbrowser.SnippetBrowser.java

/**
 * Initialise the contents of the frame.
 *//* ww  w  .  j a  v  a2  s . c o  m*/
private void initialize() {
    setTitle("Snippet Browser");
    this.setBounds(50, 50, 1000, 600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSplitPane splitPane = new JSplitPane();
    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    splitPane.setResizeWeight(0.3);
    getContentPane().add(splitPane, BorderLayout.CENTER);

    JScrollPane scrollPaneLeft = new JScrollPane();
    splitPane.setLeftComponent(scrollPaneLeft);

    treeSnippets = new JTree();
    scrollPaneLeft.setViewportView(treeSnippets);

    JScrollPane scrollPaneRight = new JScrollPane();
    splitPane.setRightComponent(scrollPaneRight);

    txtrInfo = new JTextArea();
    txtrInfo.setEditable(false);
    scrollPaneRight.setViewportView(txtrInfo);
}

From source file:ZipTest.java

public ZipTestFrame() {
    setTitle("ZipTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // add the menu and the Open and Exit menu items
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");

    JMenuItem openItem = new JMenuItem("Open");
    menu.add(openItem);// ww  w  .  j ava 2  s .  co m
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            JFileChooser chooser = new JFileChooser();
            chooser.setCurrentDirectory(new File("."));
            int r = chooser.showOpenDialog(ZipTestFrame.this);
            if (r == JFileChooser.APPROVE_OPTION) {
                zipname = chooser.getSelectedFile().getPath();
                fileCombo.removeAllItems();
                scanZipFile();
            }
        }
    });

    JMenuItem exitItem = new JMenuItem("Exit");
    menu.add(exitItem);
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });

    menuBar.add(menu);
    setJMenuBar(menuBar);

    // add the text area and combo box
    fileText = new JTextArea();
    fileCombo = new JComboBox();
    fileCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            loadZipFile((String) fileCombo.getSelectedItem());
        }
    });

    add(fileCombo, BorderLayout.SOUTH);
    add(new JScrollPane(fileText), BorderLayout.CENTER);
}

From source file:de.unidue.inf.is.ezdl.gframedl.components.checkboxlist.CheckBoxListCellRenderer.java

private void initialize() {
    panel = new JPanel();
    panel.setLayout(new BorderLayout());

    choicePanel = new JPanel(new BorderLayout());

    choice = new JCheckBox();

    choicePanel.add(choice, BorderLayout.CENTER);
    choicePanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    choicePanel.setPreferredSize(new Dimension(150, 48));

    description = new JTextArea();
    description.setOpaque(true);//from w w w.ja  v a 2s  .  co  m
    description.setEditable(false);
    description.setLineWrap(true);
    description.setWrapStyleWord(true);

    description.setSize(400, 30);
    description.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    iconLabel = new JLabel();
    iconLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    choicePanel.add(iconLabel, BorderLayout.EAST);

    panel.add(choicePanel, BorderLayout.WEST);
    panel.add(description, BorderLayout.CENTER);

    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    panel.revalidate();
    panel.repaint();
}

From source file:Main.java

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

    // Initialize an empty list of buttons.
    buttonList = new Vector<JButton>(10, 10);

    // Create all the components.
    addButton = new JButton("Add a button");
    addButton.setActionCommand(ADD);//from   w  w w.  j a  va2 s. c om
    addButton.addActionListener(this);

    removeButton = new JButton("Remove a button");
    removeButton.setActionCommand(REMOVE);
    removeButton.addActionListener(this);

    buttonPanel = new JPanel(new GridLayout(1, 1));
    buttonPanel.setPreferredSize(new Dimension(200, 75));
    buttonPanel.addContainerListener(this);

    display = new JTextArea();
    display.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(display);
    scrollPane.setPreferredSize(new Dimension(200, 75));

    clearButton = new JButton("Clear text area");
    clearButton.setActionCommand(CLEAR);
    clearButton.addActionListener(this);

    c.fill = GridBagConstraints.BOTH; // Fill entire cell.
    c.weighty = 1.0; // Button area and message area have equal height.
    c.gridwidth = GridBagConstraints.REMAINDER; // end of row
    gridbag.setConstraints(scrollPane, c);
    add(scrollPane);

    c.weighty = 0.0;
    gridbag.setConstraints(clearButton, c);
    add(clearButton);

    c.weightx = 1.0; // Add/remove buttons have equal width.
    c.gridwidth = 1; // NOT end of row
    gridbag.setConstraints(addButton, c);
    add(addButton);

    c.gridwidth = GridBagConstraints.REMAINDER; // end of row
    gridbag.setConstraints(removeButton, c);
    add(removeButton);

    c.weighty = 1.0; // Button area and message area have equal height.
    gridbag.setConstraints(buttonPanel, c);
    add(buttonPanel);

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

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

private void initGUI() {
    try {/*  ww w.  jav  a 2  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();
                jTabbedPane1.addTab("jPanel1", null, jPanel1, null);
                {
                    jLabel1 = new JLabel();
                    jPanel1.add(jLabel1);
                    jLabel1.setText("\u8acb\u586b\u5165\u76ee\u9304");
                }
                {
                    srcDirText = new JTextField();
                    JCommonUtil.jTextFieldSetFilePathMouseEvent(srcDirText, true);
                    jPanel1.add(srcDirText);
                    srcDirText.setPreferredSize(new java.awt.Dimension(288, 22));
                }
                {
                    executeBtn = new JButton();
                    jPanel1.add(executeBtn);
                    executeBtn.setText("\u57f7\u884c");
                    executeBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            executeBtnPerformed();
                        }
                    });
                }
                {
                    excludeArea = new JTextArea();
                    jPanel1.add(excludeArea);
                    excludeArea.setPreferredSize(new java.awt.Dimension(418, 238));
                }
            }
        }
        pack();
        this.setSize(511, 339);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}

From source file:ContainerEventDemo.java

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

    // Initialize an empty list of buttons.
    buttonList = new Vector<JButton>(10, 10);

    // Create all the components.
    addButton = new JButton("Add a button");
    addButton.setActionCommand(ADD);/*from   ww  w  .  j a va  2s. c  o  m*/
    addButton.addActionListener(this);

    removeButton = new JButton("Remove a button");
    removeButton.setActionCommand(REMOVE);
    removeButton.addActionListener(this);

    buttonPanel = new JPanel(new GridLayout(1, 1));
    buttonPanel.setPreferredSize(new Dimension(200, 75));
    buttonPanel.addContainerListener(this);

    display = new JTextArea();
    display.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(display);
    scrollPane.setPreferredSize(new Dimension(200, 75));

    clearButton = new JButton("Clear text area");
    clearButton.setActionCommand(CLEAR);
    clearButton.addActionListener(this);

    c.fill = GridBagConstraints.BOTH; // Fill entire cell.
    c.weighty = 1.0; // Button area and message area have equal height.
    c.gridwidth = GridBagConstraints.REMAINDER; // end of row
    gridbag.setConstraints(scrollPane, c);
    add(scrollPane);

    c.weighty = 0.0;
    gridbag.setConstraints(clearButton, c);
    add(clearButton);

    c.weightx = 1.0; // Add/remove buttons have equal width.
    c.gridwidth = 1; // NOT end of row
    gridbag.setConstraints(addButton, c);
    add(addButton);

    c.gridwidth = GridBagConstraints.REMAINDER; // end of row
    gridbag.setConstraints(removeButton, c);
    add(removeButton);

    c.weighty = 1.0; // Button area and message area have equal height.
    gridbag.setConstraints(buttonPanel, c);
    add(buttonPanel);

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

From source file:DropDemo.java

private JPanel createArea() {
    String text = "Drag from or drop into this area.\nThe default action is MOVE;\nhold the Control key to COPY.";

    JTextArea area = new JTextArea();
    area.setText(text);//from  ww  w .jav a 2 s  . c o  m
    area.setDragEnabled(true);
    JScrollPane scrollPane = new JScrollPane(area);
    scrollPane.setPreferredSize(new Dimension(400, 100));
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.setBorder(BorderFactory.createTitledBorder("Text Area"));
    return panel;
}

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

private void initGUI() {
    try {/*  ww  w . ja  v a2  s .  c  o m*/
        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("", null, jPanel1, null);
                {
                    jScrollPane3 = new JScrollPane();
                    jPanel1.add(jScrollPane3, BorderLayout.CENTER);
                    jScrollPane3.setPreferredSize(new java.awt.Dimension(379, 209));
                    {
                        replaceBeforeArea = new JTextArea();
                        jScrollPane3.setViewportView(replaceBeforeArea);
                    }
                }
                {
                    jPanel3 = new JPanel();
                    jPanel1.add(jPanel3, BorderLayout.NORTH);
                    jPanel3.setPreferredSize(new java.awt.Dimension(379, 28));
                    {
                        dbToJavaRadio = new JRadioButton();
                        jPanel3.add(dbToJavaRadio);
                        dbToJavaRadio.setText("DB->Java");
                    }
                    {
                        javaToDbRadio = new JRadioButton();
                        jPanel3.add(javaToDbRadio);
                        javaToDbRadio.setText("Java->DB");
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("??", null, jPanel2, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel2.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(379, 233));
                    {
                        jScrollPane2 = new JScrollPane();
                        jScrollPane1.setViewportView(jScrollPane2);
                        jScrollPane2.setPreferredSize(new java.awt.Dimension(376, 230));
                        {
                            replaceAfterArea = new JTextArea();
                            jScrollPane2.setViewportView(replaceAfterArea);
                        }
                    }
                }
            }
            {
                jPanel4 = new JPanel();
                BorderLayout jPanel4Layout = new BorderLayout();
                jPanel4.setLayout(jPanel4Layout);
                jTabbedPane1.addTab("setter", null, jPanel4, null);
                {
                    jScrollPane4 = new JScrollPane();
                    jPanel4.add(jScrollPane4, BorderLayout.CENTER);
                    jScrollPane4.setPreferredSize(new java.awt.Dimension(379, 233));
                    {
                        getSetRelArea = new JTextArea();
                        jScrollPane4.setViewportView(getSetRelArea);
                    }
                }
            }
        }
        buttonGroup1 = new ButtonGroup();
        buttonGroup1.add(dbToJavaRadio);
        dbToJavaRadio.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                System.out.println("dbToJavaRadio.actionPerformed, event=" + evt);
                //TODO add your code for dbToJavaRadio.actionPerformed
                execute(DbJava.DB_TO_JAVA);
            }
        });
        buttonGroup1.add(javaToDbRadio);
        javaToDbRadio.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                System.out.println("javaToDbRadio.actionPerformed, event=" + evt);
                //TODO add your code for javaToDbRadio.actionPerformed
                execute(DbJava.JAVA_TO_DB);
            }
        });
        pack();
        setSize(400, 300);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}

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

private void initGUI() {
    try {/*w  ww.j av  a  2 s  . co  m*/
        ToolTipManager.sharedInstance().setInitialDelay(0);
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("hott notes - checklist", null, jPanel1, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(612, 348));
                    {
                        checkListArea = new JTextArea();
                        jScrollPane1.setViewportView(checkListArea);
                        checkListArea.addMouseListener(new MouseAdapter() {

                            String randomColor() {
                                StringBuilder sb = new StringBuilder().append("#");
                                for (int ii = 0; ii < 6; ii++) {
                                    sb.append(RandomUtil.randomChar('a', 'b', 'c', 'd', 'f', '0', '1', '2', '3',
                                            '4', '5', '6', '7', '8', '9'));
                                }
                                return sb.toString();
                            }

                            void saveXml(Document document, File file) {
                                OutputFormat format = OutputFormat.createPrettyPrint();
                                format.setEncoding("utf-16");
                                XMLWriter writer = null;
                                try {
                                    writer = new XMLWriter(new FileWriter(file), format);
                                    writer.write(document);
                                } catch (IOException e) {
                                    JCommonUtil.handleException(e);
                                } finally {
                                    if (writer != null) {
                                        try {
                                            writer.close();
                                        } catch (IOException e) {
                                            JCommonUtil.handleException(e);
                                        }
                                    }
                                }
                            }

                            public void mouseClicked(MouseEvent evt) {
                                if (!JMouseEventUtil.buttonLeftClick(2, evt)) {
                                    return;
                                }

                                if (StringUtils.isEmpty(checkListArea.getText())) {
                                    JCommonUtil
                                            ._jOptionPane_showMessageDialog_error("checklist area is empty!");
                                    return;
                                }

                                File file = JCommonUtil._jFileChooser_selectFileOnly_saveFile();
                                if (file == null) {
                                    JCommonUtil._jOptionPane_showMessageDialog_error("file is not correct!");
                                    return;
                                }

                                //XXX
                                StringTokenizer tok = new StringTokenizer(checkListArea.getText(), "\t\n\r\f");
                                List<String> list = new ArrayList<String>();
                                String tmp = null;
                                for (; tok.hasMoreElements();) {
                                    tmp = ((String) tok.nextElement()).trim();
                                    System.out.println(tmp);
                                    list.add(tmp);
                                }
                                //XXX

                                Document document = DocumentHelper.createDocument();
                                Element rootHot = document.addElement("hottnote");
                                rootHot.addAttribute("creationtime",
                                        new Timestamp(System.currentTimeMillis()).toString());
                                rootHot.addAttribute("lastmodified",
                                        new Timestamp(System.currentTimeMillis()).toString());
                                rootHot.addAttribute("type", "checklist");
                                //appearence
                                Element appearenceE = rootHot.addElement("appearence");
                                appearenceE.addAttribute("alpha", "204");
                                Element fontE = appearenceE.addElement("font");
                                fontE.addAttribute("face", "Default");
                                fontE.addAttribute("size", "0");
                                Element styleE = appearenceE.addElement("style");
                                styleE.addElement("bg2color").addAttribute("color", randomColor());
                                styleE.addElement("bgcolor").addAttribute("color", randomColor());
                                styleE.addElement("textcolor").addAttribute("color", randomColor());
                                styleE.addElement("titlecolor").addAttribute("color", randomColor());
                                //behavior
                                rootHot.addElement("behavior");
                                //content
                                Element contentE = rootHot.addElement("content");
                                Element checklistE = contentE.addElement("checklist");
                                for (String val : list) {
                                    checklistE.addElement("item").addCDATA(val);
                                }
                                //desktop
                                Element desktopE = rootHot.addElement("desktop");
                                desktopE.addElement("position").addAttribute("x", RandomUtil.numberStr(3))
                                        .addAttribute("y", RandomUtil.numberStr(3));
                                desktopE.addElement("size").addAttribute("height", "200").addAttribute("width",
                                        "200");
                                //title
                                Element titleE = rootHot.addElement("title");
                                titleE.addCDATA(StringUtils.defaultIfEmpty(checkListTitle.getText(),
                                        DateFormatUtils.format(System.currentTimeMillis(), "dd/MM/yyyy")));

                                if (!file.getName().toLowerCase().endsWith(".hottnote")) {
                                    file = new File(file.getParentFile(), file.getName() + ".hottnote");
                                }

                                saveXml(document, file);
                                JCommonUtil._jOptionPane_showMessageDialog_info("completed!\n" + file);
                            }
                        });
                    }
                }
                {
                    checkListTitle = new JTextField();
                    checkListTitle.setToolTipText("title");
                    jPanel1.add(checkListTitle, BorderLayout.NORTH);
                }
            }
        }
        pack();
        this.setSize(633, 415);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}