Java Code Examples for java.awt.Toolkit#createCustomCursor()
The following examples show how to use
java.awt.Toolkit#createCustomCursor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FontPanel.java From hottub with GNU General Public License v2.0 | 6 votes |
public FontCanvas() { this.addMouseListener( this ); this.addMouseMotionListener( this ); this.setForeground( Color.black ); this.setBackground( Color.white ); /// Creates an invisble pointer by giving it bogus image /// Possibly find a workaround for this... Toolkit tk = Toolkit.getDefaultToolkit(); byte bogus[] = { (byte) 0 }; blankCursor = tk.createCustomCursor( tk.createImage( bogus ), new Point(0, 0), "" ); zoomWindow = new JWindow( parent ) { public void paint( Graphics g ) { g.drawImage( zoomImage, 0, 0, zoomWindow ); } }; zoomWindow.setCursor( blankCursor ); zoomWindow.pack(); }
Example 2
Source File: Player.java From jclic with GNU General Public License v2.0 | 6 votes |
/** Creates and initializes the members of the {@link cursors} array. */ protected void createCursors() { try { Toolkit tk = Toolkit.getDefaultToolkit(); cursors[HAND_CURSOR] = tk.createCustomCursor(ResourceManager.getImageIcon("cursors/hand.gif").getImage(), new Point(8, 0), "hand"); cursors[OK_CURSOR] = tk.createCustomCursor(ResourceManager.getImageIcon("cursors/ok.gif").getImage(), new Point(0, 0), "ok"); cursors[REC_CURSOR] = tk.createCustomCursor(ResourceManager.getImageIcon("cursors/micro.gif").getImage(), new Point(15, 3), "record"); } catch (Exception e) { System.err.println("Error creating cursor:\n" + e); } }
Example 3
Source File: KeyStoreEntryDragGestureListener.java From keystore-explorer with GNU General Public License v3.0 | 6 votes |
/** * Drag gesture recognized. Start the drag off if valid. * * @param evt * Drag gesture event */ @Override public void dragGestureRecognized(DragGestureEvent evt) { DragEntry dragEntry = kseFrame.dragSelectedEntry(); if (dragEntry == null) { return; } ImageIcon icon = dragEntry.getImage(); // Draw image as drag cursor Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension dim = toolkit.getBestCursorSize(icon.getIconWidth(), icon.getIconHeight()); BufferedImage buffImage = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB_PRE); icon.paintIcon(evt.getComponent(), buffImage.getGraphics(), 0, 0); cursor = toolkit.createCustomCursor(buffImage, new Point(0, 0), "keystore-entry"); evt.startDrag(cursor, new KeyStoreEntryTransferable(dragEntry), this); }
Example 4
Source File: FontPanel.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public FontCanvas() { this.addMouseListener( this ); this.addMouseMotionListener( this ); this.setForeground( Color.black ); this.setBackground( Color.white ); /// Creates an invisble pointer by giving it bogus image /// Possibly find a workaround for this... Toolkit tk = Toolkit.getDefaultToolkit(); byte bogus[] = { (byte) 0 }; blankCursor = tk.createCustomCursor( tk.createImage( bogus ), new Point(0, 0), "" ); zoomWindow = new JWindow( parent ) { public void paint( Graphics g ) { g.drawImage( zoomImage, 0, 0, zoomWindow ); } }; zoomWindow.setCursor( blankCursor ); zoomWindow.pack(); }
Example 5
Source File: FontPanel.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public FontCanvas() { this.addMouseListener( this ); this.addMouseMotionListener( this ); this.setForeground( Color.black ); this.setBackground( Color.white ); /// Creates an invisble pointer by giving it bogus image /// Possibly find a workaround for this... Toolkit tk = Toolkit.getDefaultToolkit(); byte bogus[] = { (byte) 0 }; blankCursor = tk.createCustomCursor( tk.createImage( bogus ), new Point(0, 0), "" ); zoomWindow = new JWindow( parent ) { public void paint( Graphics g ) { g.drawImage( zoomImage, 0, 0, zoomWindow ); } }; zoomWindow.setCursor( blankCursor ); zoomWindow.pack(); }
Example 6
Source File: FontPanel.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public FontCanvas() { this.addMouseListener( this ); this.addMouseMotionListener( this ); this.setForeground( Color.black ); this.setBackground( Color.white ); /// Creates an invisble pointer by giving it bogus image /// Possibly find a workaround for this... Toolkit tk = Toolkit.getDefaultToolkit(); byte bogus[] = { (byte) 0 }; blankCursor = tk.createCustomCursor( tk.createImage( bogus ), new Point(0, 0), "" ); zoomWindow = new JWindow( parent ) { public void paint( Graphics g ) { g.drawImage( zoomImage, 0, 0, zoomWindow ); } }; zoomWindow.setCursor( blankCursor ); zoomWindow.pack(); }
Example 7
Source File: FontPanel.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public FontCanvas() { this.addMouseListener( this ); this.addMouseMotionListener( this ); this.setForeground( Color.black ); this.setBackground( Color.white ); /// Creates an invisble pointer by giving it bogus image /// Possibly find a workaround for this... Toolkit tk = Toolkit.getDefaultToolkit(); byte bogus[] = { (byte) 0 }; blankCursor = tk.createCustomCursor( tk.createImage( bogus ), new Point(0, 0), "" ); zoomWindow = new JWindow( parent ) { public void paint( Graphics g ) { g.drawImage( zoomImage, 0, 0, zoomWindow ); } }; zoomWindow.setCursor( blankCursor ); zoomWindow.pack(); }
Example 8
Source File: FontPanel.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public FontCanvas() { this.addMouseListener( this ); this.addMouseMotionListener( this ); this.setForeground( Color.black ); this.setBackground( Color.white ); /// Creates an invisble pointer by giving it bogus image /// Possibly find a workaround for this... Toolkit tk = Toolkit.getDefaultToolkit(); byte bogus[] = { (byte) 0 }; blankCursor = tk.createCustomCursor( tk.createImage( bogus ), new Point(0, 0), "" ); zoomWindow = new JWindow( parent ) { public void paint( Graphics g ) { g.drawImage( zoomImage, 0, 0, zoomWindow ); } }; zoomWindow.setCursor( blankCursor ); zoomWindow.pack(); }
Example 9
Source File: FontPanel.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public FontCanvas() { this.addMouseListener( this ); this.addMouseMotionListener( this ); this.setForeground( Color.black ); this.setBackground( Color.white ); /// Creates an invisble pointer by giving it bogus image /// Possibly find a workaround for this... Toolkit tk = Toolkit.getDefaultToolkit(); byte bogus[] = { (byte) 0 }; blankCursor = tk.createCustomCursor( tk.createImage( bogus ), new Point(0, 0), "" ); zoomWindow = new JWindow( parent ) { public void paint( Graphics g ) { g.drawImage( zoomImage, 0, 0, zoomWindow ); } }; zoomWindow.setCursor( blankCursor ); zoomWindow.pack(); }
Example 10
Source File: FontPanel.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public FontCanvas() { this.addMouseListener( this ); this.addMouseMotionListener( this ); this.setForeground( Color.black ); this.setBackground( Color.white ); /// Creates an invisble pointer by giving it bogus image /// Possibly find a workaround for this... Toolkit tk = Toolkit.getDefaultToolkit(); byte bogus[] = { (byte) 0 }; blankCursor = tk.createCustomCursor( tk.createImage( bogus ), new Point(0, 0), "" ); zoomWindow = new JWindow( parent ) { public void paint( Graphics g ) { g.drawImage( zoomImage, 0, 0, zoomWindow ); } }; zoomWindow.setCursor( blankCursor ); zoomWindow.pack(); }
Example 11
Source File: FontPanel.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public FontCanvas() { this.addMouseListener( this ); this.addMouseMotionListener( this ); this.setForeground( Color.black ); this.setBackground( Color.white ); /// Creates an invisble pointer by giving it bogus image /// Possibly find a workaround for this... Toolkit tk = Toolkit.getDefaultToolkit(); byte bogus[] = { (byte) 0 }; blankCursor = tk.createCustomCursor( tk.createImage( bogus ), new Point(0, 0), "" ); zoomWindow = new JWindow( parent ) { public void paint( Graphics g ) { g.drawImage( zoomImage, 0, 0, zoomWindow ); } }; zoomWindow.setCursor( blankCursor ); zoomWindow.pack(); }
Example 12
Source File: FontPanel.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public FontCanvas() { this.addMouseListener( this ); this.addMouseMotionListener( this ); this.setForeground( Color.black ); this.setBackground( Color.white ); /// Creates an invisble pointer by giving it bogus image /// Possibly find a workaround for this... Toolkit tk = Toolkit.getDefaultToolkit(); byte bogus[] = { (byte) 0 }; blankCursor = tk.createCustomCursor( tk.createImage( bogus ), new Point(0, 0), "" ); zoomWindow = new JWindow( parent ) { public void paint( Graphics g ) { g.drawImage( zoomImage, 0, 0, zoomWindow ); } }; zoomWindow.setCursor( blankCursor ); zoomWindow.pack(); }
Example 13
Source File: DefaultTransferHandler.java From freecol with GNU General Public License v2.0 | 5 votes |
/** * Get a suitable cursor for the given component. * * @param c The component to consider. * @return A suitable {@code Cursor}, or null on failure. */ private Cursor getCursor(JComponent c) { if (c instanceof JLabel && ((JLabel)c).getIcon() instanceof ImageIcon) { Toolkit tk = Toolkit.getDefaultToolkit(); ImageIcon imageIcon = ((ImageIcon)((JLabel)c).getIcon()); Dimension bestSize = tk.getBestCursorSize(imageIcon.getIconWidth(), imageIcon.getIconHeight()); if (bestSize.width == 0 || bestSize.height == 0) return null; if (bestSize.width > bestSize.height) { bestSize.height = (int)((((double)bestSize.width) / ((double)imageIcon.getIconWidth())) * imageIcon.getIconHeight()); } else { bestSize.width = (int)((((double)bestSize.height) / ((double)imageIcon.getIconHeight())) * imageIcon.getIconWidth()); } BufferedImage scaled = ImageLibrary .createResizedImage(imageIcon.getImage(), bestSize.width, bestSize.height); Point point = new Point(bestSize.width / 2, bestSize.height / 2); return tk.createCustomCursor(scaled, point, "freeColDragIcon"); } return null; }
Example 14
Source File: GLChartPanel.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Set mouse mode * * @param value Mouse mode */ @Override public final void setMouseMode(MouseMode value) { this.mouseMode = value; Image image; Toolkit toolkit = Toolkit.getDefaultToolkit(); Cursor customCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); switch (this.mouseMode) { case SELECT: customCursor = Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); break; case ZOOM_IN: image = toolkit.getImage(this.getClass().getResource("/images/zoom_in_32x32x32.png")); customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Zoom In"); break; case ZOOM_OUT: image = toolkit.getImage(this.getClass().getResource("/images/zoom_out_32x32x32.png")); customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Zoom In"); break; case PAN: image = toolkit.getImage(this.getClass().getResource("/images/Pan_Open_32x32x32.png")); customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Pan"); break; case IDENTIFER: image = toolkit.getImage(this.getClass().getResource("/images/identifer_32x32x32.png")); customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Identifer"); break; case ROTATE: image = toolkit.getImage(this.getClass().getResource("/images/rotate.png")); customCursor = toolkit.createCustomCursor(image, new Point(8, 8), "Identifer"); break; } this.setCursor(customCursor); }
Example 15
Source File: MarvinToolPanel.java From marvinproject with GNU Lesser General Public License v3.0 | 5 votes |
public void actionPerformed(ActionEvent event){ for(int i=0; i<toolCounter; i++){ if(event.getSource() == arrButtons[i]){ // Remove current settings panel if(arrTools[currentTool].getSettingsWindow() != null){ remove(arrTools[currentTool].getSettingsWindow().getContentPane()); } currentTool = i; // Set Cursor Image img = arrTools[currentTool].getCursorImage(); if(img != null){ Toolkit tk = Toolkit.getDefaultToolkit(); Cursor cursor = tk.createCustomCursor(img, arrTools[currentTool].getCursorHotSpot(), "curstomCursor"); currentImagePanel.setCursor(cursor); } else{ currentImagePanel.setCursor(Cursor.getDefaultCursor()); } // Set settings panel if(arrTools[currentTool].getSettingsWindow() != null){ add(arrTools[currentTool].getSettingsWindow().getContentPane()); } validate(); repaint(); } } }
Example 16
Source File: EventObserver.java From mochadoom with GNU General Public License v3.0 | 5 votes |
/** * NASTY hack to hide the cursor. * * Create a 'hidden' cursor by using a transparent image * ...return the invisible cursor * @author vekltron */ private Cursor createHiddenCursor() { final Toolkit tk = Toolkit.getDefaultToolkit(); final Dimension dim = tk.getBestCursorSize(2, 2); if (dim.width == 0 || dim.height == 0) { return this.initialCursor; } final BufferedImage transparent = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB); return tk.createCustomCursor(transparent, new Point(1, 1), "HiddenCursor"); }
Example 17
Source File: PanTool.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** Constructor. */ public PanTool() { Toolkit tk = Toolkit.getDefaultToolkit(); ImageIcon imgIcon = new ImageIcon(getClass().getResource(CURSOR_IMAGE)); cursor = tk.createCustomCursor(imgIcon.getImage(), CURSOR_HOTSPOT, TOOL_NAME); panning = false; }
Example 18
Source File: Mouse.java From haxademic with MIT License | 5 votes |
public static void setInvisibleCursor(Component comp) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Point hotSpot = new Point(0,0); BufferedImage cursorImage = new BufferedImage(1, 1, BufferedImage.TRANSLUCENT); Cursor invisibleCursor = toolkit.createCustomCursor(cursorImage, hotSpot, "InvisibleCursor"); comp.setCursor(invisibleCursor); }
Example 19
Source File: CursorX.java From Forsythia with GNU General Public License v3.0 | 4 votes |
static void setCursor(Grid grid){ Toolkit tk=Toolkit.getDefaultToolkit(); Dimension cdim=tk.getBestCursorSize(UI.GRID_CURSORXSIZE,UI.GRID_CURSORXSIZE); Point hotspot=new Point(cdim.width/2,cdim.height/2); Cursor c=tk.createCustomCursor(image,hotspot,NAME); grid.setCursor(c);}
Example 20
Source File: CursorSquare.java From Forsythia with GNU General Public License v3.0 | 4 votes |
static void setCursor(Grid grid){ Toolkit tk=Toolkit.getDefaultToolkit(); Dimension cdim=tk.getBestCursorSize(UI.GRID_CURSORSQUARESIZE,UI.GRID_CURSORSQUARESIZE); Point hotspot=new Point(cdim.width/2,cdim.height/2); Cursor c=tk.createCustomCursor(image,hotspot,NAME); grid.setCursor(c);}