List of utility methods to do JTextArea
JTextArea | makeLabelStyle(JTextArea textArea) Make a JTextArea to look like a JLabel if (textArea == null) return null; textArea.setEditable(false); textArea.setCursor(null); textArea.setOpaque(false); textArea.setFocusable(false); return textArea; |
JTextArea | makeTabMoveFocus(JTextArea textArea) Based on Green, Roedy. textArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, new HashSet(Arrays.asList(new Object[] { KeyStroke.getKeyStroke("TAB") }))); textArea.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, new HashSet(Arrays.asList(new Object[] { KeyStroke.getKeyStroke("shift TAB") }))); return textArea; |
OutputStream | out(final JTextArea ta) out return new OutputStream() { public void write(int b) throws IOException { ta.append(String.valueOf((char) b)); }; |
void | preventInputingNewLineOnTextArea(JTextArea txe, AbstractAction actionOnEnter) prevent Inputing New Line On Text Area if (actionOnEnter == null) { actionOnEnter = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { }; txe.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), actionOnEnter); ... |
void | printExceptionInfo(Exception e, JTextArea console) print Exception Info console.append(e.getMessage()); printStackTrace(e, console); |
void | printInfo(JTextArea txtInfo, String infoString) print Info if (txtInfo != null) { txtInfo.append(infoString); try { txtInfo.setCaretPosition(txtInfo.getLineStartOffset(txtInfo.getLineCount() - 1)); } catch (BadLocationException e) { } else System.out.println(infoString); ... |
void | printInTextArea(JTextArea log, String[] toPrint) print In Text Area for (int i = 0; i < toPrint.length; i++) log.append(toPrint[i] + NEWLINE); |
void | printStackTrace(Exception e, JTextArea console) print Stack Trace StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); console.append(pw.toString()); |
PrintStream | printStream(final JTextArea ta) print Stream return new PrintStream(out(ta)) { public void println(String line) { ta.append(line + "\n"); }; |
void | registerUndoManager(JTextArea textArea) register Undo Manager final UndoManager undo = new UndoManager(); Document doc = textArea.getDocument(); doc.addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { undo.addEdit(evt.getEdit()); }); textArea.getActionMap().put("Undo", new AbstractAction("Undo") { ... |