-
Painting from a Graphics object?
I'm having trouble getting my head around Graphics objects and the paint method. Here's my predicament:
I have a class called DrawSurface which extends JPanel. The only thing that I changed was the paint method which I will use to draw on the DrawSurface. I have a bunch of coordinates that I want to draw onto the DrawSurface. It's not all going to fit on the screen, so I want to use a scrollbar to pan along the drawing. Is there a way that I can draw the entire drawing onto an offscreen Graphics object and then display a portion of that Graphics object on the DrawSurface depending on where the scrollbar is? I know that it's possible to draw a portion of an Image object onto a Graphics object, but what about Graphics to Graphics. Or is there an easier way that I'm overlooking?
-
Wow, why is it always that right after I ask a question I end up figuring it out?
I created a BufferedImage object called img and created a Graphics object using img.getGraphics(). Whatever I draw on the Graphics object gets added to the BufferedImage and then I can use drawImage to paint a portion onto another Graphics object.
Confusing, but I guess it makes sense.
-
Another question, might as well post it in the same thread.
Is it possible to specify exact width/height of characters that are being drawn to a graphics object? The only method I can see of altering size is the setFont method, but that only lets you do font size.
-
Well I didn't find how to set the width of a font, but I found how to find the length of a string in pixels. I just used the FontMetrics class. I found out how to do it here:
http://www.javalobby.org/forums/thre...16925&tstart=0
-
by the way: it's a nice approach to do make an big offscreen image and just show a clip.
but why don't you use the JScrollPane? It just suports that. And has scrollbars included already
-
I was thinking about doing it that way, but this worked out fine.
Similar Threads
-
Replies: 2
Last Post: 01-10-2006, 11:34 AM
-
By Michael Culley in forum .NET
Replies: 5
Last Post: 05-06-2002, 02:25 AM
-
By Michael Culley in forum .NET
Replies: 1
Last Post: 05-05-2002, 12:02 PM
-
By Jaco de Villiers in forum XML
Replies: 1
Last Post: 06-01-2001, 05:50 PM
-
By Tom Shreve in forum Enterprise
Replies: 0
Last Post: 04-07-2000, 08:15 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks