List of usage examples for javax.swing JTextArea JTextArea
public JTextArea(int rows, int columns)
From source file:QueryDB.java
public QueryDBFrame() { setTitle("QueryDB"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); setLayout(new GridBagLayout()); authors = new JComboBox(); authors.setEditable(false);// w ww. ja v a 2 s .c om authors.addItem("Any"); publishers = new JComboBox(); publishers.setEditable(false); publishers.addItem("Any"); result = new JTextArea(4, 50); result.setEditable(false); priceChange = new JTextField(8); priceChange.setText("-5.00"); try { conn = getConnection(); Statement stat = conn.createStatement(); String query = "SELECT Name FROM Authors"; ResultSet rs = stat.executeQuery(query); while (rs.next()) authors.addItem(rs.getString(1)); rs.close(); query = "SELECT Name FROM Publishers"; rs = stat.executeQuery(query); while (rs.next()) publishers.addItem(rs.getString(1)); rs.close(); stat.close(); } catch (SQLException e) { for (Throwable t : e) result.append(t.getMessage()); } catch (IOException e) { result.setText("" + e); } // we use the GBC convenience class of Core Java Volume 1 Chapter 9 add(authors, new GBC(0, 0, 2, 1)); add(publishers, new GBC(2, 0, 2, 1)); JButton queryButton = new JButton("Query"); queryButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { executeQuery(); } }); add(queryButton, new GBC(0, 1, 1, 1).setInsets(3)); JButton changeButton = new JButton("Change prices"); changeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { changePrices(); } }); add(changeButton, new GBC(2, 1, 1, 1).setInsets(3)); add(priceChange, new GBC(3, 1, 1, 1).setFill(GBC.HORIZONTAL)); add(new JScrollPane(result), new GBC(0, 2, 4, 1).setFill(GBC.BOTH).setWeight(100, 100)); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { try { if (conn != null) conn.close(); } catch (SQLException e) { for (Throwable t : e) t.printStackTrace(); } } }); }
From source file:edu.ku.brc.specify.toycode.FixSQLString.java
@Override public void createUI() { super.createUI(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,10px,f:p:g")); //$NON-NLS-1$ //$NON-NLS-2$ CellConstraints cc = new CellConstraints(); srcTA = new JTextArea(10, 80); dstTA = new JTextArea(10, 80); pb.add(UIHelper.createScrollPane(srcTA, true), cc.xy(1, 1)); pb.add(UIHelper.createScrollPane(dstTA, true), cc.xy(1, 3)); srcTA.getDocument().addDocumentListener(new DocumentAdaptor() { @Override/*from www .j av a2 s .c o m*/ protected void changed(DocumentEvent e) { String str = srcTA.getText(); if (str.length() > 0) { if (StringUtils.contains(str, "\"")) { fixFromtextToSQL(); } else { fix(); } } else { dstTA.setText(""); } } }); contentPanel = pb.getPanel(); mainPanel.add(contentPanel, BorderLayout.CENTER); okBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); pack(); }
From source file:components.FileChooserDemo2.java
public FileChooserDemo2() { super(new BorderLayout()); //Create the log first, because the action listener //needs to refer to it. log = new JTextArea(5, 20); log.setMargin(new Insets(5, 5, 5, 5)); log.setEditable(false);/*w w w.jav a 2 s . c om*/ JScrollPane logScrollPane = new JScrollPane(log); JButton sendButton = new JButton("Attach..."); sendButton.addActionListener(this); add(sendButton, BorderLayout.PAGE_START); add(logScrollPane, BorderLayout.CENTER); }
From source file:edu.ku.brc.specify.extras.FixSQLString.java
@Override public void createUI() { super.createUI(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,10px,f:p:g")); //$NON-NLS-1$ //$NON-NLS-2$ CellConstraints cc = new CellConstraints(); srcTA = new JTextArea(10, 80); dstTA = new JTextArea(10, 80); pb.add(UIHelper.createScrollPane(srcTA, true), cc.xy(1, 1)); pb.add(UIHelper.createScrollPane(dstTA, true), cc.xy(1, 3)); srcTA.getDocument().addDocumentListener(new DocumentAdaptor() { @Override/*w w w. j a v a 2s . c o m*/ protected void changed(DocumentEvent e) { String str = srcTA.getText(); if (str.length() > 0) { if (StringUtils.contains(str, "\"")) { fixFromTextToSQL(); } else { fix(); } } else { dstTA.setText(""); } } }); contentPanel = pb.getPanel(); mainPanel.add(contentPanel, BorderLayout.CENTER); okBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); pack(); }
From source file:TextDemo.java
public TextDemo() { super(new GridBagLayout()); textField = new JTextField(20); textField.addActionListener(this); textArea = new JTextArea(5, 20); textArea.setEditable(false);/*from ww w.java 2s.co m*/ JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); //Add Components to this panel. GridBagConstraints c = new GridBagConstraints(); c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; add(textField, c); c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; c.weighty = 1.0; add(scrollPane, c); }
From source file:SwingDnDTest.java
public SwingDnDFrame() { setTitle("SwingDnDTest"); JTabbedPane tabbedPane = new JTabbedPane(); JList list = SampleComponents.list(); tabbedPane.addTab("List", list); JTable table = SampleComponents.table(); tabbedPane.addTab("Table", table); JTree tree = SampleComponents.tree(); tabbedPane.addTab("Tree", tree); JFileChooser fileChooser = new JFileChooser(); tabbedPane.addTab("File Chooser", fileChooser); JColorChooser colorChooser = new JColorChooser(); tabbedPane.addTab("Color Chooser", colorChooser); final JTextArea textArea = new JTextArea(4, 40); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setBorder(new TitledBorder(new EtchedBorder(), "Drag text here")); JTextField textField = new JTextField("Drag color here"); textField.setTransferHandler(new TransferHandler("background")); tabbedPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { textArea.setText(""); }//w w w . j av a2 s. co m }); tree.setDragEnabled(true); table.setDragEnabled(true); list.setDragEnabled(true); fileChooser.setDragEnabled(true); colorChooser.setDragEnabled(true); textField.setDragEnabled(true); add(tabbedPane, BorderLayout.NORTH); add(scrollPane, BorderLayout.CENTER); add(textField, BorderLayout.SOUTH); pack(); }
From source file:GetApplets.java
private void createGUI() { JPanel contentPane = new JPanel(new BorderLayout()); contentPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK), BorderFactory.createEmptyBorder(10, 10, 10, 10))); setContentPane(contentPane);/* ww w .j a v a2s. c o m*/ JButton b = new JButton("Click to call getApplets()"); b.addActionListener(this); add(b, BorderLayout.PAGE_START); textArea = new JTextArea(5, 40); textArea.setEditable(false); JScrollPane scroller = new JScrollPane(textArea); add(scroller, BorderLayout.CENTER); }
From source file:components.JWSFileChooserDemo.java
public JWSFileChooserDemo() { super(new BorderLayout()); //Create the log first, because the action listeners //need to refer to it. log = new JTextArea(5, 20); log.setMargin(new Insets(5, 5, 5, 5)); log.setEditable(false);/*from ww w . j a va 2 s . c o m*/ JScrollPane logScrollPane = new JScrollPane(log); //Create the open button. We use the image from the JLF //Graphics Repository (but we extracted it from the jar). openButton = new JButton("Open a File...", createImageIcon("images/Open16.gif")); openButton.addActionListener(this); //Create the save button. We use the image from the JLF //Graphics Repository (but we extracted it from the jar). saveButton = new JButton("Save a File...", createImageIcon("images/Save16.gif")); saveButton.addActionListener(this); //For layout purposes, put the buttons in a separate panel JPanel buttonPanel = new JPanel(); buttonPanel.add(openButton); buttonPanel.add(saveButton); //Add the buttons and the log to this panel. add(buttonPanel, BorderLayout.PAGE_START); add(logScrollPane, BorderLayout.CENTER); }
From source file:HtmlDemo.java
public HtmlDemo() { setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); String initialText = "<html>\n" + "Color and font test:\n" + "<ul>\n" + "<li><font color=red>red</font>\n" + "<li><font color=blue>blue</font>\n" + "<li><font color=green>green</font>\n" + "<li><font size=-2>small</font>\n" + "<li><font size=+2>large</font>\n" + "<li><i>italic</i>\n" + "<li><b>bold</b>\n" + "</ul>\n"; htmlTextArea = new JTextArea(10, 20); htmlTextArea.setText(initialText);/* w ww. j a va2 s . c o m*/ JScrollPane scrollPane = new JScrollPane(htmlTextArea); JButton changeTheLabel = new JButton("Change the label"); changeTheLabel.setMnemonic(KeyEvent.VK_C); changeTheLabel.setAlignmentX(Component.CENTER_ALIGNMENT); changeTheLabel.addActionListener(this); theLabel = new JLabel(initialText) { public Dimension getPreferredSize() { return new Dimension(200, 200); } public Dimension getMinimumSize() { return new Dimension(200, 200); } public Dimension getMaximumSize() { return new Dimension(200, 200); } }; theLabel.setVerticalAlignment(SwingConstants.CENTER); theLabel.setHorizontalAlignment(SwingConstants.CENTER); JPanel leftPanel = new JPanel(); leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS)); leftPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Edit the HTML, then click the button"), BorderFactory.createEmptyBorder(10, 10, 10, 10))); leftPanel.add(scrollPane); leftPanel.add(Box.createRigidArea(new Dimension(0, 10))); leftPanel.add(changeTheLabel); JPanel rightPanel = new JPanel(); rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.PAGE_AXIS)); rightPanel .setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("A label with HTML"), BorderFactory.createEmptyBorder(10, 10, 10, 10))); rightPanel.add(theLabel); setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); add(leftPanel); add(Box.createRigidArea(new Dimension(10, 0))); add(rightPanel); }
From source file:jmap2gml.ScriptGui.java
/** * Formats the window, initializes the JMap2Script object, and sets up all * the necessary events.//from w w w . j a va 2 s . c om */ public ScriptGui() { setTitle("jmap to gml script converter"); setDefaultCloseOperation(EXIT_ON_CLOSE); getContentPane().setLayout(new GridBagLayout()); this.addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent we) { } @Override public void windowClosing(WindowEvent we) { saveConfig(); } @Override public void windowClosed(WindowEvent we) { } @Override public void windowIconified(WindowEvent we) { } @Override public void windowDeiconified(WindowEvent we) { } @Override public void windowActivated(WindowEvent we) { } @Override public void windowDeactivated(WindowEvent we) { } }); GridBagConstraints c = new GridBagConstraints(); setResizable(true); setIconImage((new ImageIcon("spikeup.png")).getImage()); jta = new JTextArea(38, 30); loadConfig(); JScrollPane jsp = new JScrollPane(jta); jsp.setRowHeaderView(new TextLineNumber(jta)); jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); jsp.setSize(jsp.getWidth(), 608); // menu bar JMenuBar menubar = new JMenuBar(); // file menu JMenu file = new JMenu("File"); // load button JMenuItem load = new JMenuItem("Load jmap"); load.addActionListener(ae -> { JFileChooser fileChooser = new JFileChooser(prevDirectory); fileChooser.setFileFilter(new FileNameExtensionFilter("jmap file", "jmap", "jmap")); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); prevDirectory = selectedFile.getAbsolutePath(); jm2s = new ScriptFromJmap(selectedFile.getPath(), false); jta.setText(""); jta.append(jm2s.toString()); jta.setCaretPosition(0); writeFile.setEnabled(true); drawPanel.setItems(jta.getText().split("\n")); } }); // add load to file menu file.add(load); // button to save script to file writeFile = new JMenuItem("Write file"); writeFile.addActionListener(ae -> { if (jm2s != null) { PrintWriter out; try { File f = new File( jm2s.getFileName().substring(0, jm2s.getFileName().lastIndexOf(".jmap")) + ".gml"); out = new PrintWriter(f); out.append(jm2s.toString()); out.close(); } catch (FileNotFoundException ex) { Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex); } } }); writeFile.setEnabled(false); JMenuItem gmx = new JMenuItem("Export as gmx"); gmx.addActionListener(ae -> { String fn = String.format("%s.room.gmx", prevDirectory); JFileChooser fc = new JFileChooser(prevDirectory); fc.setSelectedFile(new File(fn)); fc.setFileFilter(new FileNameExtensionFilter("Game Maker XML", "gmx", "gmx")); fc.showDialog(null, "Save"); File f = fc.getSelectedFile(); if (f != null) { try { GMX.itemsToGMX(drawPanel.items, new FileOutputStream(f)); } catch (FileNotFoundException ex) { Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex); } } }); // add to file menu file.add(writeFile); file.add(gmx); // add file menu to the menubar menubar.add(file); // Edit menu // display menu JMenu display = new JMenu("Display"); JMenuItem update = new JMenuItem("Update"); update.addActionListener(ae -> { drawPanel.setItems(jta.getText().split("\n")); }); display.add(update); JMenuItem gridToggle = new JMenuItem("Toggle Grid"); gridToggle.addActionListener(ae -> { drawPanel.toggleGrid(); }); display.add(gridToggle); JMenuItem gridOptions = new JMenuItem("Modify Grid"); gridOptions.addActionListener(ae -> { drawPanel.modifyGrid(); }); display.add(gridOptions); menubar.add(display); // sets the menubar setJMenuBar(menubar); // add the text area to the window c.gridx = 0; c.gridy = 0; add(jsp, c); // initialize the preview panel drawPanel = new Preview(this); JScrollPane scrollPane = new JScrollPane(drawPanel); // add preview panel to the window c.gridx = 1; c.gridwidth = 2; add(scrollPane, c); pack(); setMinimumSize(this.getSize()); setLocationRelativeTo(null); setVisible(true); drawPanel.setItems(jta.getText().split("\n")); }