Example usage for javax.swing.text DefaultCaret setUpdatePolicy

List of usage examples for javax.swing.text DefaultCaret setUpdatePolicy

Introduction

In this page you can find the example usage for javax.swing.text DefaultCaret setUpdatePolicy.

Prototype

public void setUpdatePolicy(int policy) 

Source Link

Document

Sets the caret movement policy on the document updates.

Usage

From source file:org.n52.ifgicopter.spf.input.PostgisInputPlugin.java

@Override
public void init() throws Exception {
    log.info("initializing ...");

    // create GUI
    this.gui = new ModuleGUI();
    this.panel = new JPanel();
    this.panel.setLayout(new BorderLayout());
    this.panel.add(makeControlPanel(), BorderLayout.NORTH);
    this.panel.add(makeStatusLabel(), BorderLayout.SOUTH);
    this.textArea = new JTextArea();
    this.textArea.setEditable(false);
    DefaultCaret caret = (DefaultCaret) this.textArea.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    JScrollPane scrollPane = new JScrollPane(this.textArea);
    this.panel.add(scrollPane, BorderLayout.CENTER);

    this.gui.setMenu(makeMenu());
    this.gui.setGui(this.panel);

    // try loading the database driver
    try {//  w w  w . j a va2  s.  co  m
        Class.forName(this.driver);
    } catch (ClassNotFoundException e) {
        log.error(e);
    }

    // create database connection
    Connector connector = new Connector(this);
    this.futureConnection = Executors.newSingleThreadExecutor().submit(connector);

    log.info("initialized.");
}

From source file:org.spoutcraft.launcher.skin.ConsoleFrame.java

/**
 * Build the interface.//ww w . j  a  v  a  2s.  c o m
 */
private void buildUI() {
    if (colorEnabled) {
        JTextPane text = new JTextPane();
        this.textComponent = text;
    } else {
        JTextArea text = new JTextArea();
        this.textComponent = text;
        text.setLineWrap(true);

    }
    textComponent.addMouseListener(this);
    textComponent.setFont(getMonospaceFont());
    textComponent.setEditable(false);
    DefaultCaret caret = (DefaultCaret) textComponent.getCaret();
    caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    document = textComponent.getDocument();
    document.addDocumentListener(new LimitLinesDocumentListener(numLines, true));

    JScrollPane scrollText = new JScrollPane(textComponent);
    scrollText.setBorder(null);
    scrollText.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    add(scrollText, BorderLayout.CENTER);
}

From source file:processing.app.EditorTab.java

/**
 * Replace the entire contents of this tab.
 */// w w w . j av  a 2 s .  c o m
public void setText(String what) {
    // Remove all highlights, since these will all end up at the start of the
    // text otherwise. Preserving them is tricky, so better just remove them.
    textarea.removeAllLineHighlights();
    // Set the caret update policy to NEVER_UPDATE while completely replacing
    // the current text. Normally, the caret tracks inserts and deletions, but
    // replacing the entire text will always make the caret end up at the end,
    // which isn't really useful. With NEVER_UPDATE, the caret will just keep
    // its absolute position (number of characters from the start), which isn't
    // always perfect, but the best we can do without making a diff of the old
    // and new text and some guesswork.
    // Note that we cannot use textarea.setText() here, since that first removes
    // text and then inserts the new text. Even with NEVER_UPDATE, the caret
    // always makes sure to stay valid, so first removing all text makes it
    // reset to 0. Also note that simply saving and restoring the caret position
    // will work, but then the scroll position might change in response to the
    // caret position.
    DefaultCaret caret = (DefaultCaret) textarea.getCaret();
    int policy = caret.getUpdatePolicy();
    caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    try {
        Document doc = textarea.getDocument();
        int oldLength = doc.getLength();
        // The undo manager already seems to group the insert and remove together
        // automatically, but better be explicit about it.
        textarea.beginAtomicEdit();
        try {
            doc.insertString(oldLength, what, null);
            doc.remove(0, oldLength);
        } catch (BadLocationException e) {
            System.err.println("Unexpected failure replacing text");
        } finally {
            textarea.endAtomicEdit();
        }
    } finally {
        caret.setUpdatePolicy(policy);
    }
}

From source file:uk.sipperfly.ui.Exactly.java

private void editCurrentStatusPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_editCurrentStatusPropertyChange
    // TODO add your handling code here:
    this.editCurrentStatus.setEditable(false);
    this.editCurrentStatus.setLineWrap(true);
    this.editCurrentStatus.setWrapStyleWord(true);
    DefaultCaret caret = (DefaultCaret) this.editCurrentStatus.getCaret();
    caret.setUpdatePolicy(ALWAYS_UPDATE);
}

From source file:uk.sipperfly.ui.Exactly.java

private void currentTemplatePropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_currentTemplatePropertyChange
    this.currentTemplate.setEditable(false);
    this.currentTemplate.setLineWrap(true);
    this.currentTemplate.setWrapStyleWord(true);
    DefaultCaret caret = (DefaultCaret) this.currentTemplate.getCaret();
    caret.setUpdatePolicy(ALWAYS_UPDATE);
}