Example usage for javax.swing JTextPane setCursor

List of usage examples for javax.swing JTextPane setCursor

Introduction

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

Prototype

public void setCursor(Cursor cursor) 

Source Link

Document

Sets the cursor image to the specified cursor.

Usage

From source file:Main.java

public static final void main(String[] args) throws Exception {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextPane textPane = new JTextPane();
    textPane.addMouseMotionListener(new MouseAdapter() {
        public void mouseMoved(MouseEvent e) {
            AttributeSet style = getAttributes(e);
            if (style != null && StyleConstants.getIcon(style) != null) {
                textPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            } else {
                textPane.setCursor(Cursor.getDefaultCursor());
            }//from   ww w. ja v a 2s  .  c o m
        }
    });
    frame.add(new JScrollPane(textPane));

    StyledDocument doc = (StyledDocument) textPane.getDocument();

    SimpleAttributeSet style = new SimpleAttributeSet();
    StyleConstants.setIcon(style, createImage());

    doc.insertString(doc.getLength(), "this is a test", null);
    doc.insertString(doc.getLength(), "test", style);
    doc.insertString(doc.getLength(), "this is a test\n", null);
    doc.insertString(doc.getLength(), "another image", style);

    frame.pack();
    frame.setLocationByPlatform(true);
    frame.setVisible(true);

}

From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java

public JTextPane createJTextPane(String text) {
    JTextPane jtp = new JTextPane();
    jtp.setText(text);/*from   w ww .j a  v  a2  s  . c om*/
    SimpleAttributeSet underline = new SimpleAttributeSet();
    StyleConstants.setUnderline(underline, true);
    jtp.getStyledDocument().setCharacterAttributes(0, text.length(), underline, true);
    jtp.setEditable(false);
    jtp.setOpaque(false);
    jtp.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));
    jtp.setBorder(BorderFactory.createEmptyBorder());
    jtp.setForeground(Color.blue);
    jtp.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    return jtp;
}

From source file:org.languagetool.gui.ResultArea.java

ResultArea(final ResourceBundle messages, final LanguageToolSupport ltSupport, final JTextPane statusPane) {
    this.messages = messages;
    this.ltSupport = ltSupport;
    this.statusPane = statusPane;
    statusPane.setContentType("text/html");
    statusPane.setText(Main.HTML_GREY_FONT_START + messages.getString("resultAreaText") + Main.HTML_FONT_END);
    statusPane.setEditable(false);// www . j av a 2  s. c  om
    statusPane.addHyperlinkListener(new MyHyperlinkListener());
    statusPane.setTransferHandler(new RetainLineBreakTransferHandler());
    ltSupport.addLanguageToolListener(new LanguageToolListener() {
        @Override
        public void languageToolEventOccurred(LanguageToolEvent event) {
            if (event.getType() == LanguageToolEvent.Type.CHECKING_STARTED) {
                final Language lang = ltSupport.getLanguage();
                final String langName;
                if (lang.isExternal()) {
                    langName = lang.getTranslatedName(messages) + Main.EXTERNAL_LANGUAGE_SUFFIX;
                } else {
                    langName = lang.getTranslatedName(messages);
                }
                final String startCheckText = Main.HTML_GREY_FONT_START
                        + Tools.makeTexti18n(messages, "startChecking", langName) + "..." + Main.HTML_FONT_END;
                statusPane.setText(startCheckText);
                setStartText(startCheckText);
                if (event.getCaller() == marker) {
                    statusPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                }
            } else if (event.getType() == LanguageToolEvent.Type.CHECKING_FINISHED) {
                inputText = event.getSource().getTextComponent().getText();
                setRuleMatches(event.getSource().getMatches());
                if (event.getCaller() == marker || event.getCaller() == null) {
                    displayResult();
                    if (event.getCaller() == marker) {
                        statusPane.setCursor(Cursor.getDefaultCursor());
                    }
                }
            } else if (event.getType() == LanguageToolEvent.Type.RULE_DISABLED
                    || event.getType() == LanguageToolEvent.Type.RULE_ENABLED) {
                inputText = event.getSource().getTextComponent().getText();
                setRuleMatches(event.getSource().getMatches());
                displayResult();
            }
        }
    });
}