下面列出了java.awt.Cursor#HAND_CURSOR 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
/**
* Create the GUI.
*
* @throws IOException
*/
public DualSub() throws IOException {
// Look and feel
try {
// UIManager.setLookAndFeel(new NimbusLookAndFeel());
UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
JFrame.setDefaultLookAndFeelDecorated(false);
JDialog.setDefaultLookAndFeelDecorated(false);
// UIManager.setLookAndFeel(UIManager
// .getCrossPlatformLookAndFeelClassName());
// JFrame.setDefaultLookAndFeelDecorated(true);
// JDialog.setDefaultLookAndFeelDecorated(true);
} catch (Exception e) {
log.warn(e.getMessage());
}
splash = new Splash(ClassLoader.getSystemResource("img/splash.png"));
cursor = new Cursor(Cursor.HAND_CURSOR);
loadProperties();
// Default language
String locale = preferences.get("locale",
properties.getProperty("locale"));
if (!locale.isEmpty()) {
I18N.setLocale(locale);
}
initialize();
menu = new Menu(this, locale);
menu.addMenu(leftFileListener, rightFileListener, folderListener,
mergeButtonListener);
showFrame();
}