Java Code Examples for javax.swing.JTextPane#setCursor()

The following examples show how to use javax.swing.JTextPane#setCursor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HyperlinkSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseMoved(MouseEvent e) {
    JTextPane pane = (JTextPane)e.getSource();
    StyledDocument doc = pane.getStyledDocument();
    Element elem = doc.getCharacterElement(pane.viewToModel(e.getPoint()));
    AttributeSet as = elem.getAttributes();
    if (StyleConstants.isUnderline(as)) {
        pane.setCursor(new Cursor(Cursor.HAND_CURSOR));
    } else {
        pane.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}
 
Example 2
Source File: VersionPane.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
public void mouseMoved(MouseEvent ev) {
JTextPane editor = (JTextPane) ev.getSource();
editor.setEditable(false);
  Point pt = new Point(ev.getX(), ev.getY());
  int pos = editor.viewToModel(pt);
  if (pos >= 0) {
    Document eDoc = editor.getDocument();
    if (eDoc instanceof DefaultStyledDocument) {
      DefaultStyledDocument hdoc =
        (DefaultStyledDocument) eDoc;
      Element e = hdoc.getCharacterElement(pos);
      AttributeSet a = e.getAttributes();
      AttributeSet tagA = (AttributeSet) a.getAttribute(HTML.Tag.A);
      String href = null;
      if (tagA!=null){
          href = (String)tagA.getAttribute(HTML.Attribute.HREF);
      }
      if (href != null) {
          editor.setToolTipText(href);
          if (editor.getCursor().getType() != Cursor.HAND_CURSOR) {
              editor.setCursor(new Cursor(Cursor.HAND_CURSOR));
          }
      }
      else {
          editor.setToolTipText(null);
          if (editor.getCursor().getType() != Cursor.DEFAULT_CURSOR) {
              editor.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
      }
    }
  }
  else {
      editor.setToolTipText(null);
  }
}
 
Example 3
Source File: ApplicationXML.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected JComponent getTextComponent(String locator) throws Exception {
    JTextPane textComponent = new JTextPane();
    textComponent.setText(getContent(locator));
    textComponent.setFont(new Font("monospaced", Font.PLAIN, 12));
    textComponent.setEditable(false);
    textComponent.setCaretPosition(0);
    textComponent.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
    return textComponent;
}
 
Example 4
Source File: Text.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
protected JComponent getTextComponent(String locator) throws Exception {
    JTextPane textComponent = new JTextPane();
    textComponent.setText(getContent(locator));
    textComponent.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
    textComponent.setEditable(false);
    textComponent.setCaretPosition(0);
    return textComponent;
}