List of usage examples for javax.swing JTextArea append
public void append(String str)
From source file:UndoExample1.java
public static void main(String[] args) { try {//from w w w . j av a 2 s . co m UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new UndoExample1(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(250, 300); f.setVisible(true); // Create and show a frame monitoring undoable edits JFrame undoMonitor = new JFrame("Undo Monitor"); final JTextArea textArea = new JTextArea(); textArea.setEditable(false); undoMonitor.getContentPane().add(new JScrollPane(textArea)); undoMonitor.setBounds(f.getLocation().x + f.getSize().width, f.getLocation().y, 400, 200); undoMonitor.setVisible(true); pane.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { UndoableEdit edit = evt.getEdit(); textArea.append(edit.getPresentationName() + "(" + edit.toString() + ")\n"); } }); // Create and show a frame monitoring document edits JFrame editMonitor = new JFrame("Edit Monitor"); final JTextArea textArea2 = new JTextArea(); textArea2.setEditable(false); editMonitor.getContentPane().add(new JScrollPane(textArea2)); editMonitor.setBounds(undoMonitor.getLocation().x, undoMonitor.getLocation().y + undoMonitor.getSize().height, 400, 200); editMonitor.setVisible(true); pane.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent evt) { textArea2.append("Attribute change\n"); } public void insertUpdate(DocumentEvent evt) { textArea2.append("Text insertion\n"); } public void removeUpdate(DocumentEvent evt) { textArea2.append("Text removal\n"); } }); }
From source file:UndoExample5.java
public static void main(String[] args) { try {/*from w w w . j a v a2 s .co m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new UndoExample5(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(250, 300); f.setVisible(true); // Create and show a frame monitoring undoable edits JFrame undoMonitor = new JFrame("Undo Monitor"); final JTextArea textArea = new JTextArea(); textArea.setEditable(false); undoMonitor.getContentPane().add(new JScrollPane(textArea)); undoMonitor.setBounds(f.getLocation().x + f.getSize().width, f.getLocation().y, 400, 200); undoMonitor.setVisible(true); pane.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { UndoableEdit edit = evt.getEdit(); textArea.append(edit.getPresentationName() + "(" + edit.toString() + ")\n"); } }); // Create and show a frame monitoring document edits JFrame editMonitor = new JFrame("Edit Monitor"); final JTextArea textArea2 = new JTextArea(); textArea2.setEditable(false); editMonitor.getContentPane().add(new JScrollPane(textArea2)); editMonitor.setBounds(undoMonitor.getLocation().x, undoMonitor.getLocation().y + undoMonitor.getSize().height, 400, 200); editMonitor.setVisible(true); pane.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent evt) { textArea2.append("Attribute change\n"); } public void insertUpdate(DocumentEvent evt) { textArea2.append("Text insertion\n"); } public void removeUpdate(DocumentEvent evt) { textArea2.append("Text removal\n"); } }); }
From source file:SelectingComboSample.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "J", "I" }; JFrame frame = new JFrame("Selecting JComboBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JComboBox comboBox = new JComboBox(labels); contentPane.add(comboBox, BorderLayout.SOUTH); final JTextArea textArea = new JTextArea(); textArea.setEditable(false);//from ww w. j a v a 2 s. co m JScrollPane sp = new JScrollPane(textArea); contentPane.add(sp, BorderLayout.CENTER); ItemListener itemListener = new ItemListener() { public void itemStateChanged(ItemEvent itemEvent) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); int state = itemEvent.getStateChange(); String stateString = ((state == ItemEvent.SELECTED) ? "Selected" : "Deselected"); pw.print("Item: " + itemEvent.getItem()); pw.print(", State: " + stateString); ItemSelectable is = itemEvent.getItemSelectable(); pw.print(", Selected: " + selectedString(is)); pw.println(); textArea.append(sw.toString()); } }; comboBox.addItemListener(itemListener); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.print("Command: " + actionEvent.getActionCommand()); ItemSelectable is = (ItemSelectable) actionEvent.getSource(); pw.print(", Selected: " + selectedString(is)); pw.println(); textArea.append(sw.toString()); } }; comboBox.addActionListener(actionListener); frame.setSize(400, 200); frame.setVisible(true); }
From source file:ModifyModelSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Modifying Model"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); // Fill model final DefaultListModel model = new DefaultListModel(); for (int i = 0, n = labels.length; i < n; i++) { model.addElement(labels[i]);/* w w w . j a va2s. c o m*/ } JList jlist = new JList(model); JScrollPane scrollPane1 = new JScrollPane(jlist); contentPane.add(scrollPane1, BorderLayout.WEST); final JTextArea textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane2 = new JScrollPane(textArea); contentPane.add(scrollPane2, BorderLayout.CENTER); ListDataListener listDataListener = new ListDataListener() { public void contentsChanged(ListDataEvent listDataEvent) { appendEvent(listDataEvent); } public void intervalAdded(ListDataEvent listDataEvent) { appendEvent(listDataEvent); } public void intervalRemoved(ListDataEvent listDataEvent) { appendEvent(listDataEvent); } private void appendEvent(ListDataEvent listDataEvent) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); switch (listDataEvent.getType()) { case ListDataEvent.CONTENTS_CHANGED: pw.print("Type: Contents Changed"); break; case ListDataEvent.INTERVAL_ADDED: pw.print("Type: Interval Added"); break; case ListDataEvent.INTERVAL_REMOVED: pw.print("Type: Interval Removed"); break; } pw.print(", Index0: " + listDataEvent.getIndex0()); pw.print(", Index1: " + listDataEvent.getIndex1()); DefaultListModel theModel = (DefaultListModel) listDataEvent.getSource(); Enumeration elements = theModel.elements(); pw.print(", Elements: "); while (elements.hasMoreElements()) { pw.print(elements.nextElement()); pw.print(","); } pw.println(); textArea.append(sw.toString()); } }; model.addListDataListener(listDataListener); // Setup buttons JPanel jp = new JPanel(new GridLayout(2, 1)); JPanel jp1 = new JPanel(new FlowLayout(FlowLayout.CENTER, 1, 1)); JPanel jp2 = new JPanel(new FlowLayout(FlowLayout.CENTER, 1, 1)); jp.add(jp1); jp.add(jp2); JButton jb = new JButton("add F"); jp1.add(jb); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { model.add(0, "First"); } }); jb = new JButton("addElement L"); jp1.add(jb); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { model.addElement("Last"); } }); jb = new JButton("insertElementAt M"); jp1.add(jb); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int size = model.getSize(); model.insertElementAt("Middle", size / 2); } }); jb = new JButton("set F"); jp1.add(jb); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int size = model.getSize(); if (size != 0) model.set(0, "New First"); } }); jb = new JButton("setElementAt L"); jp1.add(jb); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int size = model.getSize(); if (size != 0) model.setElementAt("New Last", size - 1); } }); jb = new JButton("load 10"); jp1.add(jb); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { for (int i = 0, n = labels.length; i < n; i++) { model.addElement(labels[i]); } } }); jb = new JButton("clear"); jp2.add(jb); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { model.clear(); } }); jb = new JButton("remove F"); jp2.add(jb); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int size = model.getSize(); if (size != 0) model.remove(0); } }); jb = new JButton("removeAllElements"); jp2.add(jb); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { model.removeAllElements(); } }); jb = new JButton("removeElement 'Last'"); jp2.add(jb); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { model.removeElement("Last"); } }); jb = new JButton("removeElementAt M"); jp2.add(jb); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int size = model.getSize(); if (size != 0) model.removeElementAt(size / 2); } }); jb = new JButton("removeRange FM"); jp2.add(jb); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int size = model.getSize(); if (size != 0) model.removeRange(0, size / 2); } }); contentPane.add(jp, BorderLayout.SOUTH); frame.setSize(640, 300); frame.setVisible(true); }
From source file:Main.java
public static OutputStream out(final JTextArea ta) { return new OutputStream() { public void write(int b) throws IOException { ta.append(String.valueOf((char) b)); }/*from w w w. j a v a 2s .c om*/ }; }
From source file:com.enderville.enderinstaller.util.InstallScript.java
/** * Installs the specified list of mods, updating the gui as it goes. * * @param mods The list of mods to install. * @param text The text area to update with logging statements. * @param progressBar The progress bar to update. *///from w w w . j a va2 s .c om public static void guiInstall(List<String> mods, JTextArea text, JProgressBar progressBar) { //Create backups to restore if the install fails. try { createBackup(); } catch (IOException e) { text.append("Failed to create backup copies of minecraft.jar and mods folder"); LOGGER.error("Failed to create backup copies of minecraft.jar and mods folder", e); return; } //Create a temp directory where we can unpack the jar and install mods. File tmp; try { tmp = getTempDir(); } catch (IOException e) { text.append("Error creating temp directory!"); LOGGER.error("Install Error", e); return; } if (!tmp.mkdirs()) { text.append("Error creating temp directory!"); return; } File mcDir = new File(InstallerConfig.getMinecraftFolder()); File mcJar = new File(InstallerConfig.getMinecraftJar()); File reqDir = new File(InstallerConfig.getRequiredModsFolder()); //Calculate the number of "tasks" for the progress bar. int reqMods = 0; for (File f : reqDir.listFiles()) { if (f.isDirectory()) { reqMods++; } } //3 "other" steps: unpack, repack, delete temp int baseTasks = 3; int taskSize = reqMods + mods.size() + baseTasks; progressBar.setMinimum(0); progressBar.setMaximum(taskSize); int task = 1; try { text.append("Unpacking minecraft.jar\n"); unpackMCJar(tmp, mcJar); progressBar.setValue(task++); text.append("Installing Core mods\n"); //TODO specific ordering required! for (File mod : reqDir.listFiles()) { if (!mod.isDirectory()) { continue; } String name = mod.getName(); text.append("...Installing " + name + "\n"); installMod(mod, tmp, mcDir); progressBar.setValue(task++); } if (!mods.isEmpty()) { text.append("Installing Extra mods\n"); //TODO specific ordering required! for (String name : mods) { File mod = new File(FilenameUtils .normalize(FilenameUtils.concat(InstallerConfig.getExtraModsFolder(), name))); text.append("...Installing " + name + "\n"); installMod(mod, tmp, mcDir); progressBar.setValue(task++); } } text.append("Repacking minecraft.jar\n"); repackMCJar(tmp, mcJar); progressBar.setValue(task++); } catch (Exception e) { text.append("!!!Error installing mods!!!"); LOGGER.error("Installation error", e); try { restoreBackup(); } catch (IOException ioe) { text.append("Error while restoring backup files minecraft.jar.backup and mods_backup folder\n!"); LOGGER.error("Error while restoring backup files minecraft.jar.backup and mods_backup folder!", ioe); } } text.append("Deleting temporary files\n"); try { FileUtils.deleteDirectory(tmp); progressBar.setValue(task++); } catch (IOException e) { text.append("Error deleting temporary files!\n"); LOGGER.error("Install Error", e); return; } text.append("Finished!"); }
From source file:ConsoleWindowTest.java
public static void init() { JFrame frame = new JFrame(); frame.setTitle("ConsoleWindow"); final JTextArea output = new JTextArea(); output.setEditable(false);//from www . j a va2s. c om frame.add(new JScrollPane(output)); frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); frame.setLocation(DEFAULT_LEFT, DEFAULT_TOP); frame.setFocusableWindowState(false); frame.setVisible(true); // define a PrintStream that sends its bytes to the output text area PrintStream consoleStream = new PrintStream(new OutputStream() { public void write(int b) { } // never called public void write(byte[] b, int off, int len) { output.append(new String(b, off, len)); } }); // set both System.out and System.err to that stream System.setOut(consoleStream); System.setErr(consoleStream); }
From source file:biomine.bmvis2.pipeline.ManualGroupOperation.java
@Override public JComponent getSettingsComponent(SettingsChangeCallback v, VisualGraph graph) { ArrayList<VisualNode> vns = new ArrayList<VisualNode>(); JTextArea text = new JTextArea(); text.append("Group of:\n"); for (VisualNode n : graph.getAllNodes()) { if (nodes.contains(n.getId())) { text.append(n.getName() + "\n"); }// ww w . j a va2 s . c o m } return text; }
From source file:Main.java
public Console() { JTextArea textArea = new JTextArea(24, 80); textArea.setBackground(Color.BLACK); textArea.setForeground(Color.LIGHT_GRAY); textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); System.setOut(new PrintStream(new OutputStream() { @Override// w w w . j ava 2 s . c om public void write(int b) throws IOException { textArea.append(String.valueOf((char) b)); } })); frame.add(textArea); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.ImportDataFileInfo.java
/** * shows modified (truncated) data after import *//*from ww w . ja v a 2 s. c om*/ protected void showModifiedData() { if (importer.getTruncations().size() > 0) { JPanel mainPane = new JPanel(new BorderLayout()); JLabel msg = createLabel(getResourceString("WB_TRUNCATIONS")); msg.setFont(msg.getFont().deriveFont(Font.BOLD)); mainPane.add(msg, BorderLayout.NORTH); String[] heads = new String[3]; String[][] vals = new String[importer.getTruncations().size()][3]; heads[0] = getResourceString("WB_ROW"); heads[1] = getResourceString("WB_COLUMN"); heads[2] = getResourceString("WB_TRUNCATED"); int row = 0; for (DataImportTruncation trunc : importer.getTruncations()) { vals[row][0] = String.valueOf(trunc.getRow()); vals[row][1] = trunc.getColHeader(); if (vals[row][1].equals("")) { vals[row][1] = String.valueOf(trunc.getCol() + 1); } vals[row++][2] = trunc.getExcluded(); } JTable mods = new JTable(vals, heads); mods.setDefaultRenderer(String.class, new BiColorTableCellRenderer(false)); mainPane.add(UIHelper.createScrollPane(mods), BorderLayout.CENTER); CustomFrame cwin = new CustomFrame(getResourceString(MODIFIED_IMPORT_DATA), CustomFrame.OKHELP, mainPane); cwin.setHelpContext("WorkbenchImportData"); //help context could be more specific cwin.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); UIHelper.centerAndShow(cwin); } if (importer.getMessages().size() > 0) { JPanel mainPane = new JPanel(new BorderLayout()); JTextArea msgs = new JTextArea(); msgs.setRows(importer.getMessages().size()); for (String msg : importer.getMessages()) { msgs.append(msg); msgs.append("\n"); } mainPane.add(msgs, BorderLayout.CENTER); CustomFrame cwin = new CustomFrame(getResourceString(MODIFIED_IMPORT_DATA), CustomFrame.OKHELP, mainPane); cwin.setHelpContext("WorkbenchImportData"); //help context could be more specific cwin.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); UIHelper.centerAndShow(cwin); } }