Java 2D is an API for drawing two-dimensional graphics using the Java programming language.
Questions tagged [java-2d]
1076 questions
7
votes
1 answer
Mouse pointer detection over a Path2D
I have constructed a Path2D that represents an unclosed shape consisting of straight lines:
I want to be able to detect when the mouse is clicked and the mouse pointer is near to (within a few pixels of) the path. Using the contains method does…

Adamski
- 54,009
- 15
- 113
- 152
7
votes
0 answers
Java Swing deprecated in favor of JavaFx 2.0
Am I correct that Oracle has deprecated Swing and that JavaFx 2.0 is it's official replacement?
This makes sense to me because it would seem kind of goofy for oracle to maintain the development of two competing api's that do pretty much the same…

Marc H
- 1,228
- 3
- 18
- 29
7
votes
3 answers
Drawing a Component to BufferedImage causes display corruption
I am using the JScrollNavigator component described here, in order to provide a navigation window onto a large "canvas-like" CAD component I have embedded within a JScrollPane.
I have tried to adapt the JScrollNavigator to draw a thumbnail image of…

Adamski
- 54,009
- 15
- 113
- 152
6
votes
2 answers
Accessing font kerning information in Java2D
Little background..
I'm in the process of making an OpenGL game using Java and LWJGL. I've written a TextRenderer-class that renders text using cached pages of glyphs. The glyphs itself are rendered in Java2D to BufferedImages and packed into…

MH114
- 975
- 1
- 9
- 13
6
votes
3 answers
Does anyone know of a java2d text library?
This is what I need in my game regarding text:
Word Wrap Support given a bounding box
Vertical and Horizontal alignment given a bounding box
Now, I've been reading about how to use TextLayout, and it seems possible to write all this myself but I'd…

Daniel Kaplan
- 62,768
- 50
- 234
- 356
6
votes
3 answers
How to render a 2d image in Java
I have a quick question about Java. I'm sorry if this question is really basic, but I'm a beginner Java programmer :D
I want to render a 2d image in a window, but I can't figure it out. I've looked at the graphics API here:…

Steve
- 63
- 1
- 1
- 4
6
votes
2 answers
How to create a curve between 2 points in 2D and get back Points that makes that curve every d distance?
I'm not good in math.
I have 2 points, A(x1, y1) and B(x2, y2) in 2D.
I need to create a virtual path from point A to B curved at R(radius), and then return an array of points which are describing this curved path, not all maybe every D(distance)…

Paweł
- 2,144
- 1
- 18
- 25
6
votes
3 answers
Java2D Graphics anti-aliased
I am new to Java and trying to use Java2D Graphics to create a Image. But the output is coming as anti-aliased. I tried many ways to rectify it but doesn't work. The characters are getting distorted or jagged.
public BufferedImage…

Prakash
- 69
- 1
- 1
- 5
6
votes
1 answer
Align text with Java Graphics 2d
Can anyone tell me how to alight text right in Java 2d?
Here's the code, it draws a column of text that is naturally aligned left.
Font yFont = new Font("Arial", Font.BOLD, 13);
interval = 0;
g2d.setFont(yFont);
for (String l : binLabels) {
…

slotishtype
- 2,715
- 7
- 32
- 47
6
votes
3 answers
Draw ring with given thickness, position, and radius. (Java2D)
I need to draw a ring, with given thickness, that looks something like this:
The center must be transparent, so that it doesn't cover previously drawn shapes. (or other rings) I've tried something like this:
//g is a Graphics2D…

ostrichofevil
- 749
- 7
- 19
6
votes
4 answers
Very weird Java2D setClip() effect - bug?
I want to create a dialog with a custom shape and transparency, think info bubble pointing to some component.
To do so, I add a JPanel to a JDialog and overwrite the paintComponent(Graphics) method of the panel. The panel itself contains regular…

Marco
- 1,430
- 10
- 18
6
votes
6 answers
Java 2D: Moving a point P a certain distance closer to another point?
What is the best way to go about moving a Point2D.Double x distance closer to another Point2D.Double?
Edit: Tried to edit, but so went down for maintenance. No this is not homework
I need to move a plane (A) towards the end of a runway (C) and…
user75832
6
votes
2 answers
Problem in generating the border of a rectangle in Java?
I am using java.awt.geom.Rectangle2D.Double class to generate a rectangle. I want to generate a rectangle which is filled with a color (say green) and have a border (outline).
Now the problem is if I call
g2.draw(new Rectangle2D.Double(....)); // g2…

Amit
- 33,847
- 91
- 226
- 299
6
votes
4 answers
Fastest way to compare pixel values between two BufferedImages?
I have a BufferedImage of type TYPE_INT_BGR. I need to do a pixel-by-pixel comparison to another BufferedImage to compute the "distance" between the two images. I have something that works, but is slow. I get a pixel from the "reference" image,…

George Armhold
- 30,824
- 50
- 153
- 232
6
votes
3 answers
Text antialiasing broken in Java 1.7 (Windows)
Antialiasing rendering hints for text seem broken for Swing components Java 1.7 (Windows). Setting KEY_ANTIALIASING and/or KEY_TEXT_ANTIALIASING does not affect anymore the display of JLabel, JEditorPane, etc. - but actually I need different…

sina72
- 4,931
- 3
- 35
- 36