Results 1 to 5 of 5
- 06-02-2009, 10:04 PM #1
Member
- Join Date
- Oct 2008
- Location
- UK
- Posts
- 65
- Rep Power
- 0
[SOLVED] Custom Cursors: Thick Lines
I wanted to create my own custom cursor so I wrote some code to create a BufferedImage then I use this to create a cursor. I wanted to avoid having an image file because this is something I then have to distribute with my software.
The code below creates this cursor, it works, and also draws a rectangle by comparison.
My problem is that the lines in the cursor are incredibly thick. Is there any way around this? I'd like them to be thinner.
Java Code:public class Main { public static Cursor GetMyCursor() { Image image = GetMyImage(); Point hotSpot = new Point(0,0); return Toolkit.getDefaultToolkit().createCustomCursor(image, hotSpot, "my cursor"); } public static Image GetMyImage() { int width = 10; int height = 10; BufferedImage image = new BufferedImage(width,height, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = image.createGraphics(); graphics.setColor(Color.BLACK); graphics.drawLine(0, 0, 0, 6); graphics.drawLine(0, 0, 6, 0); graphics.drawLine(3, 2, 3, 4); graphics.drawLine(2, 3, 4, 3); return image; } /** * @param args the command line arguments */ public static void main(String[] args) { JFrame test = new JFrame(); test.add(new MyFrame()); test.setPreferredSize(new Dimension(200,200)); test.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); test.pack(); test.setCursor(GetMyCursor()); test.setVisible(true); } public static class MyFrame extends JPanel { protected @Override void paintComponent(Graphics g) { g.drawRect(10,10,20,20); } } }
- 06-02-2009, 10:43 PM #2
Graphics2D.setStroke() should sort it.
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
-
The stroke may not help here as your image is being magnified more than two fold. I think the problem is that your image size is less then half the size of a cursor, and so Swing has to magnify the image to get it to fit a cursor's size. Instead, try this:
and I'll bet things will work better.Java Code:public static Image GetMyImage() { int width = 32; int height = 32;
- 06-03-2009, 01:44 AM #4
Ah, good spot
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 06-03-2009, 09:56 AM #5
Member
- Join Date
- Oct 2008
- Location
- UK
- Posts
- 65
- Rep Power
- 0
Similar Threads
-
SWT List w/ colored lines?
By p!lle in forum SWT / JFaceReplies: 1Last Post: 03-23-2009, 03:23 PM -
Anyway to fix the lines so they dun shift?
By PeterFeng in forum New To JavaReplies: 0Last Post: 01-14-2009, 10:26 AM -
Random Lines
By Urgle in forum New To JavaReplies: 29Last Post: 11-12-2008, 03:42 PM -
how to edit lines.
By jason27131 in forum New To JavaReplies: 1Last Post: 08-01-2007, 04:41 AM -
How to draw a thick line
By johnt in forum Java 2DReplies: 1Last Post: 05-31-2007, 04:27 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks