
OK then. Let’s get started. This tutorial will teach you how to
change the cursor icon which is used to display the location of the
mouse, to one of the other predefined Icons in the Java Abstract Window
Toolkit (and hence, Java Swing).
You change the cursor using
2 | Cursor curse = new Cursor(Cursor.CROSSHAIR_CURSOR); |
3 | Cursor curse = Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); |
You set the cursor of any Swing Component using the
setCursor() method.
4 | JPanel myPanel = new JPanel(); |
5 | myPanel.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR); |
Here is a sample program:
04 | public class MainApp extends JFrame{ |
13 | setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); |
16 | public static void main(String[] args){ |
18 | try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
22 | SwingUtilities.invokeLater( new Runnable(){ |
No comments:
Post a Comment