List of usage examples for javax.swing JTextArea JTextArea
public JTextArea()
From source file:kenh.xscript.elements.Debug.java
private void initial(Container c) { c.setLayout(new BorderLayout()); // Add variable list DefaultListModel<String> model = new DefaultListModel(); if (this.getEnvironment() != null) { java.util.Set<String> keys = this.getEnvironment().getVariables().keySet(); for (String key : keys) { model.addElement(key);//from w ww . j av a 2 s .c om } } else { for (int i = 1; i < 10; i++) { model.addElement("Variable " + i); } model.addElement("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); } JList list = new JList(model); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane listPane = new JScrollPane(); listPane.setViewportView(list); listPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); c.add(listPane, BorderLayout.EAST); list.setPreferredSize(new Dimension(150, list.getPreferredSize().height)); // JTextField quote = new JTextField(); quote.requestFocus(); //JButton button = new JButton(">>"); JPanel quotePanel = new JPanel(); quotePanel.setLayout(new BorderLayout()); quotePanel.add(quote, BorderLayout.CENTER); //quotePanel.add(button, BorderLayout.EAST); JTextArea result = new JTextArea(); result.setEditable(false); JScrollPane resultPane = new JScrollPane(); resultPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); resultPane.setViewportView(result); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add(quotePanel, BorderLayout.NORTH); panel.add(resultPane, BorderLayout.CENTER); c.add(panel, BorderLayout.CENTER); list.addListSelectionListener(this); //button.addActionListener(this); quote.addKeyListener(this); this.result = result; }
From source file:events.MouseWheelEventDemo.java
public MouseWheelEventDemo() { super(new BorderLayout()); textArea = new JTextArea(); textArea.setEditable(false);/*from www . j a va 2 s. c o m*/ scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new Dimension(400, 250)); add(scrollPane, BorderLayout.CENTER); textArea.append("This text area displays information " + "about its mouse wheel events." + NEWLINE); //Register for mouse-wheel events on the text area. textArea.addMouseWheelListener(this); setPreferredSize(new Dimension(450, 350)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:events.MouseEventDemo.java
public MouseEventDemo() { super(new GridLayout(0, 1)); blankArea = new BlankArea(Color.YELLOW); add(blankArea);/*from w w w .j ava 2 s .co m*/ textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new Dimension(200, 75)); add(scrollPane); //Register for mouse events on blankArea and the panel. blankArea.addMouseListener(this); addMouseListener(this); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:gtu._work.ui._DefaultJFrameUI.java
private void initGUI() { try {/* www . j a v a 2 s . co 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); { srcPathText = new JTextField(); JCommonUtil.jTextFieldSetFilePathMouseEvent(srcPathText, true); jPanel1.add(srcPathText); srcPathText.setPreferredSize(new java.awt.Dimension(291, 24)); } { executeBtn = new JButton(); jPanel1.add(executeBtn); executeBtn.setText("\u57f7\u884c"); executeBtn.setPreferredSize(new java.awt.Dimension(66, 39)); executeBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { executeBtnActionPerformed(evt); } }); } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("jPanel2", null, jPanel2, null); { jScrollPane1 = new JScrollPane(); jPanel2.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(533, 334)); { logArea = new JTextArea(); jScrollPane1.setViewportView(logArea); logArea.setText(""); } } } } pack(); this.setSize(554, 401); } catch (Exception e) { //add your error handling code here e.printStackTrace(); } }
From source file:gtu._work.ui.RegexTestUI.java
private void initGUI() { try {//from www . j a v a 2 s . co m DocumentListener docListener = JCommonUtil.getDocumentListener(new HandleDocumentEvent() { public void process(DocumentEvent event) { jText1OrJArea1Change(event); } }); BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); { jTabbedPane1 = new JTabbedPane(); jTabbedPane1.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { jText1OrJArea1Change(null); } }); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("src text", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); { srcArea = new JTextArea(); jScrollPane1.setViewportView(srcArea); srcArea.setBorder( BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0))); JCommonUtil.setFont(srcArea); srcArea.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { jText1OrJArea1Change(null); } }); } } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("group", null, jPanel2, null); { jScrollPane2 = new JScrollPane(); jPanel2.add(jScrollPane2, BorderLayout.CENTER); jScrollPane2.setPreferredSize(new java.awt.Dimension(398, 234)); { ListModel groupListModel = new DefaultComboBoxModel(); groupList = new JList(); jScrollPane2.setViewportView(groupList); groupList.setBorder( BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0))); groupList.setModel(groupListModel); JCommonUtil.setFont(groupList); } } { regexText0 = new JTextField(); jPanel2.add(regexText0, BorderLayout.NORTH); regexText0.setBorder( BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0))); JCommonUtil.setFont(regexText0); regexText0.getDocument().addDocumentListener(docListener); } } { jPanel3 = new JPanel(); BorderLayout jPanel3Layout = new BorderLayout(); jPanel3.setLayout(jPanel3Layout); jTabbedPane1.addTab("scanner", null, jPanel3, null); { jScrollPane3 = new JScrollPane(); jPanel3.add(jScrollPane3, BorderLayout.CENTER); { ListModel scannerListModel = new DefaultComboBoxModel(); scannerList = new JList(); jScrollPane3.setViewportView(scannerList); scannerList.setBorder( BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0))); scannerList.setModel(scannerListModel); JCommonUtil.setFont(scannerList); } } { regexText = new JTextField(); jPanel3.add(regexText, BorderLayout.NORTH); regexText.setBorder( BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0))); JCommonUtil.setFont(regexText); regexText.getDocument().addDocumentListener(docListener); } } } this.setTitle("\u6b63\u5247\u8868\u793a\u5f0f"); this.setSize(419, 320); } catch (Exception e) { e.printStackTrace(); } }
From source file:events.MouseMotionEventDemo.java
public MouseMotionEventDemo() { super(new GridLayout(0, 1)); blankArea = new BlankArea(Color.YELLOW); add(blankArea);/* www . jav a 2s . c o m*/ textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setPreferredSize(new Dimension(200, 75)); add(scrollPane); //Register for mouse events on blankArea and panel. blankArea.addMouseMotionListener(this); addMouseMotionListener(this); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:ClassTree.java
public ClassTreeFrame() { setTitle("ClassTree"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // the root of the class tree is Object root = new DefaultMutableTreeNode(java.lang.Object.class); model = new DefaultTreeModel(root); tree = new JTree(model); // add this class to populate the tree with some data addClass(getClass());//from w ww.j a va 2 s .c om // set up node icons ClassNameTreeCellRenderer renderer = new ClassNameTreeCellRenderer(); renderer.setClosedIcon(new ImageIcon("red-ball.gif")); renderer.setOpenIcon(new ImageIcon("yellow-ball.gif")); renderer.setLeafIcon(new ImageIcon("blue-ball.gif")); tree.setCellRenderer(renderer); // set up selection mode tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent event) { // the user selected a different node--update description TreePath path = tree.getSelectionPath(); if (path == null) return; DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) path.getLastPathComponent(); Class<?> c = (Class<?>) selectedNode.getUserObject(); String description = getFieldDescription(c); textArea.setText(description); } }); int mode = TreeSelectionModel.SINGLE_TREE_SELECTION; tree.getSelectionModel().setSelectionMode(mode); // this text area holds the class description textArea = new JTextArea(); // add tree and text area JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1, 2)); panel.add(new JScrollPane(tree)); panel.add(new JScrollPane(textArea)); add(panel, BorderLayout.CENTER); addTextField(); }
From source file:gtu._work.ui.SaveFileToPropertiesUI.java
private void initGUI() { try {// ww w .j a v a2 s .c om BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); this.setTitle("save file to properties"); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("load", null, jPanel1, null); { jScrollPane2 = new JScrollPane(); jPanel1.add(jScrollPane2, BorderLayout.CENTER); { textArea = new JTextArea(); jScrollPane2.setViewportView(textArea); } } { jPanel2 = new JPanel(); jPanel1.add(jPanel2, BorderLayout.NORTH); jPanel2.setPreferredSize(new java.awt.Dimension(400, 40)); { addPropsFile = new JButton(); jPanel2.add(addPropsFile); addPropsFile.setText("load properties from file"); addPropsFile.setPreferredSize(new java.awt.Dimension(234, 30)); addPropsFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectFileOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("file is not correct!", "ERROR"); return; } try { props.load(new InputStreamReader(new FileInputStream(file), (String) openUnknowFilecharSet.getSelectedItem())); reloadPropertiesTable(); } catch (Exception e) { JCommonUtil.handleException(e); } } }); } { openFile = new JButton(); jPanel2.add(openFile); openFile.setText("open unknow file"); openFile.setPreferredSize(new java.awt.Dimension(204, 30)); openFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectFileOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("file is not correct!", "ERROR"); return; } try { String encode = (String) openUnknowFilecharSet.getSelectedItem(); BufferedReader reader = new BufferedReader( new InputStreamReader(new FileInputStream(file), encode)); StringBuilder sb = new StringBuilder(); for (String line = null; (line = reader.readLine()) != null;) { sb.append(line + "\n"); } reader.close(); textArea.setText(textArea.getText() + "\n" + sb); } catch (IOException e) { JCommonUtil.handleException(e); } } }); } { ComboBoxModel openUnknowFilecharSetModel = new DefaultComboBoxModel( new String[] { "BIG5", "UTF8" }); openUnknowFilecharSet = new JComboBox(); jPanel2.add(openUnknowFilecharSet); openUnknowFilecharSet.setModel(openUnknowFilecharSetModel); openUnknowFilecharSet.setPreferredSize(new java.awt.Dimension(73, 24)); } { appendTextAreaToProps = new JButton(); jPanel2.add(appendTextAreaToProps); appendTextAreaToProps.setText("append textarea to properties"); appendTextAreaToProps.setPreferredSize(new java.awt.Dimension(227, 30)); appendTextAreaToProps.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (StringUtils.isBlank(textArea.getText())) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("textArea is empty", "ERROR"); return; } try { BufferedReader reader = new BufferedReader( new StringReader(textArea.getText())); int pos = -1; String key = null; String value = null; for (String line = null; (line = reader.readLine()) != null;) { if ((pos = line.lastIndexOf("=")) != -1) { key = line.substring(0, pos); value = line.substring(pos + 1); props.put(key, value); } } reader.close(); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("append success!", "SUCCESS"); reloadPropertiesTable(); } catch (IOException e) { JCommonUtil.handleException(e); } } }); } } } { jPanel3 = new JPanel(); BorderLayout jPanel3Layout = new BorderLayout(); jPanel3.setLayout(jPanel3Layout); jTabbedPane1.addTab("props edit", null, jPanel3, null); { jScrollPane1 = new JScrollPane(); jPanel3.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(629, 361)); { TableModel propsTableModel = new DefaultTableModel(); propsTable = new JTable(); jScrollPane1.setViewportView(propsTable); propsTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (propsTable.getRowCount() == 0) { return; } int rowPos = JTableUtil.newInstance(propsTable).getSelectedRow(); Object key = propsTable.getValueAt(rowPos, 0); Object value = propsTable.getValueAt(rowPos, 1); JMenuItem insertRowItem = JTableUtil.newInstance(propsTable) .jMenuItem_addRow(false, null); insertRowItem.setText("inert row..."); String rowInfo = "delete row : [" + key + "] = [" + value + "]"; JMenuItem delRowItem = JTableUtil.newInstance(propsTable) .jMenuItem_removeRow("are you sure remove row : \n" + rowInfo); delRowItem.setText(rowInfo); JPopupMenuUtil.newInstance(propsTable).applyEvent(evt) .addJMenuItem(insertRowItem, delRowItem).show(); } }); propsTable.setModel(propsTableModel); JTableUtil.defaultSetting(propsTable); } } { jPanel4 = new JPanel(); jPanel3.add(jPanel4, BorderLayout.SOUTH); jPanel4.setPreferredSize(new java.awt.Dimension(629, 45)); { clearProps = new JButton(); jPanel4.add(clearProps); clearProps.setText("clear properties"); clearProps.setPreferredSize(new java.awt.Dimension(182, 36)); clearProps.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { props.clear(); reloadPropertiesTable(); } }); } { savePropsToFile = new JButton(); jPanel4.add(savePropsToFile); savePropsToFile.setText("save properties to file"); savePropsToFile.setPreferredSize(new java.awt.Dimension(182, 36)); savePropsToFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectFileOnly().showSaveDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("file is not correct!", "ERROR"); return; } try { props.clear(); DefaultTableModel model = (DefaultTableModel) propsTable.getModel(); Object key = null; Object value = null; for (int ii = 0; ii < model.getRowCount(); ii++) { key = model.getValueAt(ii, 0); value = model.getValueAt(ii, 1); props.put(key, value); } props.store(new FileOutputStream(file), SaveFileToPropertiesUI.class.getSimpleName()); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("save completed!\n" + file, "SUCCESS"); } catch (IOException e) { JCommonUtil.handleException(e); } } }); } } } } pack(); this.setSize(798, 505); } catch (Exception e) { e.printStackTrace(); } }
From source file:dbmods.InsertTemplateName.java
private void addLogWindow() { //START >> jInfoArea jInfoArea = new JTextArea(); scrollPane = new JScrollPane(jInfoArea); scrollPane.setViewportView(jInfoArea); getContentPane().add(scrollPane, BorderLayout.CENTER); Rectangle rect = new Rectangle(22, 223, 350, 115); scrollPane.setBounds(rect);/* w ww . ja v a 2 s . com*/ jInfoArea.setEditable(false); jInfoArea.setLineWrap(true); jInfoArea.setWrapStyleWord(true); jInfoArea.setBounds(rect); //END << jInfoArea }
From source file:ModalMessage.java
/** * This method initializes jTextArea //from w ww. ja v a 2 s . c om * * @return javax.swing.JTextArea */ private JTextArea getJTextArea() { if (jTextArea == null) { jTextArea = new JTextArea(); jTextArea.setEditable(false); // Generated jTextArea.setLineWrap(true); // Generated } return jTextArea; }