Java Utililty Methods JTextArea

List of utility methods to do JTextArea

Description

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

Method

voidaddMessageLogger(JTextArea t)
Add the given component into the list of components that show messages from the message method calls
messageLogs.add(t);
voidaddStyle(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);
...
voidadjustToText(JTextArea testString)
adjust To Text
testString.setColumns(columns(testString));
testString.setRows(estimatedRows(testString));
voidappendNewLine(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());
voidapplyDefaultProperties(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"); 
voidattachSimpleUndoManager(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())
...
voidblockUncomment(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());
voidclearTextArea(JTextArea textArea)
clear Text Area
if (textArea.getLineCount() > 200) {
    textArea.setText("");
intcolumns(JTextArea testString)
columns
return Math.min((int) (testString.getText().length() * 0.66), 80);
voidcommentSQL(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++;