Java 2D is an API for drawing two-dimensional graphics using the Java programming language.
Questions tagged [java-2d]
1076 questions
4
votes
2 answers
Java bug? Why draws rectangle instead of ellipse?
The code below draws rectangle and 2 ellipses.
While should draw 3 ellipses.
My OS is Windows 7 prof 64 bit
My Java is 1.6 x86 also 1.7 x64 tested.
Why?
package tests;
import java.awt.BasicStroke;
import java.awt.Color;
import…

Dims
- 47,675
- 117
- 331
- 600
4
votes
3 answers
Cannot manage to use ActionListener between two classes
I try to implement two classes, one dedicated to the interface and the other one dedicated to the canvas allowing user to draw shapes on it.
So basically, let's take one of my button, here is my Jbutton bCircle where I want to initialize the action…

Olivier C
- 41
- 5
4
votes
2 answers
Smooth Drawing using Java2d without the Opengl or Direct3d Pipelines?
I can't figure out a way to get smooth movement or animation of anything using Java2d when the opengl and direct3d pipelines are disabled (by invoking the vm with -Dsun.java2d.d3d=false and -Dsun.java2d.opengl=false)
The quick and dirty code below…
user1846344
4
votes
2 answers
Split image into clickable regions
Is there any way to split an image to region (right now it's JLabel but I can change it if necessary)?
I use swing in my program and I have an image (square for this example) with some triangles, stars and trapezoids inside it (it can be JPG, PNG,…

lsxliron
- 540
- 5
- 11
4
votes
2 answers
Draw an infinite line through 2 points?
I'm looking for a way to draw an infinite line (a line with no end, also known as a ray) through 2 points. I can draw a line between 2 points with Line2D, no problem here.
Next the infinite part needed a look. With my simple mind I thought, lets…

T. Akhayo
- 411
- 6
- 13
4
votes
2 answers
Find the intersection(s) of a pair of QuadCurve2Ds
Is there an easy way to approximate the points (if any) where two instances of QuadCurve2D intersect?
That is, how could I compute the coordinates of the red dots in this diagram? There is no obvious method in QuadCurve2D to do this.
(note: the…

finnw
- 47,861
- 24
- 143
- 221
4
votes
5 answers
Java moving rectangle faster?
So I am trying to make the popular game pong in java. I've made the player rectangle and setup the action listener so I am ready to move the player up and down on the screen. But I have run into a problem. When I am moving the player I have a choice…

Thobias Nordgaard
- 278
- 7
- 20
4
votes
2 answers
How to draw a transparent shape using a Graphics object g?
I want to create a “ring” in a BufferedImage with a transparent background. I can draw the circle with a transparent background like this:
BufferedImage bi = new BufferedImage(d, d, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D)…

Alan
- 175
- 4
- 15
4
votes
1 answer
Java2D / Graphics2D performance
Maybe there's someone out there who has spent time on this. I'm working on a graph visualization lib in Java and I just did some performance tests.
When I'm adding about 2000 vertices connected by 1000 - 3000 edges, it gets really, really slow.…

Dänu
- 5,791
- 9
- 43
- 56
4
votes
2 answers
How to make rotated text look good with Java2D
My question is not about how to rotate text with Java2D; I know how to do that. What I don't know is how to make the rotated text "look good." For example, if you create a text box in PowerPoint and rotate it, the text appears sharp and clear no…

Bill Doss
- 601
- 1
- 6
- 13
3
votes
5 answers
Low-hanging graphics programming fruits?
I'm currently working on a tile-based game in Java2D, and I was thinking of adding some cheap eye candy.
For example, implementing a simple particle system (maybe something like this) for explosions and/or smoke.
Do you have any suggestion for…

Ido Yehieli
- 75
- 4
3
votes
3 answers
Where does the origin of a graphic string start?
In core Java book it says
The width of the rectangle that the getStringBounds method returns is the horizontal
extent of the string. The height of the rectangle is the sum of ascent, descent, and
leading. The rectangle has its origin at the…

skystar7
- 4,419
- 11
- 38
- 41
3
votes
2 answers
Java2D Drawing is Flickering
I am working on a GameBoy emulator and using Java2D for drawing. However my current method of drawing is causing a lot of flickering on my Linux machine. This flickering is not present on my friend's Mac.
I should explain graphics on the GameBoy a…

tnecniv
- 587
- 2
- 5
- 12
3
votes
1 answer
Event Dispatch Thread painting
Just a quick one - I'm in the process of writing a Sega Master System emulator. The design thus far is that the GUI (JFrame subclass etc.) runs in the Event Dispatch Thread, via an EventQueue.invokeLater() call, and all the emulator functions run in…

PhilPotter1987
- 1,306
- 2
- 12
- 20
3
votes
5 answers
Paint over all other components (Swing, Java)
In my application I need to draw grid lines just like those like Photoshop has - e.g, an user can drag lines over the document to help him align layers. Now, the problem is that I am able to draw such lines (it's just plain simple Java2D painting…

Rafael Steil
- 4,538
- 4
- 25
- 30