Java Utililty Methods JTextArea

List of utility methods to do JTextArea

  1. HOME
  2. Java
  3. J
  4. JTextArea

Description

The list of methods to do JTextArea are organized into topic(s).

Method

void addMessageLogger(JTextArea t)
Add the given component into the list of components that show messages from the message method calls
messageLogs.add(t);
void addStyle(JTextArea textArea, String labelName, boolean isBorder)
add Style
Border border = null;
if (isBorder) {
 Border line = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
 TitledBorder titled = BorderFactory.createTitledBorder(line, labelName);
 titled.setTitleFont(new Font("Verdana", 0, 13));
 titled.setTitleColor(new Color(213, 225, 185));
 Border empty = new EmptyBorder(5, 8, 5, 8);
 CompoundBorder cBorder = new CompoundBorder(titled, empty);
...
void adjustToText(JTextArea testString)
adjust To Text
testString.setColumns(columns(testString));
testString.setRows(estimatedRows(testString));
void appendNewLine(final JTextArea textArea, final String line)
Appends a line and a new line to a text area.
textArea.append(line);
textArea.append("\n");
textArea.setCaretPosition(textArea.getDocument().getLength());
void applyDefaultProperties(final JTextArea comp)
Sets default background and foreground color as well as a default font for the specified component.
if (comp == null) {
 return;
applyProperties(comp, "TextArea.background", 
 "TextArea.foreground", 
 "TextArea.font"); 
void attachSimpleUndoManager(JTextArea jta)
attach Simple Undo Manager
UndoManager um = new UndoManager();
jta.getDocument().addUndoableEditListener(um);
jta.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("control Z"),
 "doUndo");
jta.getActionMap().put("doUndo", new AbstractAction() {
 @Override
 public void actionPerformed(ActionEvent e) {
 if (um.canUndo())
...
void blockUncomment(JTextArea scriptPanel)
Block uncomment the selected text in the given script panel.
final int startOffset = scriptPanel.getSelectionStart();
final int endOffset = scriptPanel.getSelectionEnd();
scriptPanel.replaceRange("", endOffset - BLOCK_COMMENT_END.length(), endOffset);
scriptPanel.replaceRange("", startOffset, startOffset + BLOCK_COMMENT_START.length());
scriptPanel.setSelectionStart(startOffset);
scriptPanel.setSelectionEnd(endOffset - BLOCK_COMMENT_START.length() - BLOCK_COMMENT_END.length());
void clearTextArea(JTextArea textArea)
clear Text Area
if (textArea.getLineCount() > 200) {
 textArea.setText("");
int columns(JTextArea testString)
columns
return Math.min((int) (testString.getText().length() * 0.66), 80);
void commentSQL(JTextArea scriptPanel, String commentCharacter)
Comment the selected text in the given script panel.
final Element root = scriptPanel.getDocument().getDefaultRootElement();
final int numberOfLastLine = root.getElementIndex(scriptPanel.getSelectionEnd());
int currentLineNumber = root.getElementIndex(scriptPanel.getSelectionStart());
while (currentLineNumber <= numberOfLastLine) {
 scriptPanel.insert(commentCharacter, root.getElement(currentLineNumber).getStartOffset());
 currentLineNumber++;


AltStyle によって変換されたページ (->オリジナル) /