List of usage examples for javax.swing JTextPane addMouseMotionListener
public synchronized void addMouseMotionListener(MouseMotionListener l)
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 . j av a 2s . c om } }); 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); }