當滑鼠在一個component上時,游標的形狀會隨著component的游標特性改變
游標特性是可以透過Component.setCursor() 改變的
下面是一個簡單的例子:
複製內容到剪貼板
代碼:
// Create a component
Component comp = new Button("OK");
// 這可以取得目前comp的游標特性,預設為Cursor.DEFAULT_CURSOR
Cursor cursor = comp.getCursor();
// 改變游標成別的形狀
comp.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
更詳細的資訊可以參考Java API內的Cursor