Example usage for javax.swing JTextPane getCaret

List of usage examples for javax.swing JTextPane getCaret

Introduction

In this page you can find the example usage for javax.swing JTextPane getCaret.

Prototype

@Transient
public Caret getCaret() 

Source Link

Document

Fetches the caret that allows text-oriented navigation over the view.

Usage

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    panel.setLayout(new BorderLayout());
    setContentPane(panel);/*from ww w  . ja v a2 s  .  co  m*/
    JTextPane textA = new JTextPane();
    textA.setName("text");
    textA.setContentType("text/html");
    DefaultCaret caret = (DefaultCaret) textA.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    JScrollPane filler = new JScrollPane(textA, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

    JTextPane textB = new JTextPane();
    textB.setName("text" + "_T");
    textB.setFont(textA.getFont());
    DefaultCaret caret_T = (DefaultCaret) textB.getCaret();
    caret_T.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    JScrollPane filler_T = new JScrollPane(textB, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    panel.add(filler, BorderLayout.NORTH);
    panel.add(filler_T, BorderLayout.CENTER);
    pack();
}