Java 2D is an API for drawing two-dimensional graphics using the Java programming language.
Questions tagged [java-2d]
1076 questions
3
votes
1 answer
java2D pawns on a chessboard drag and drop
for a school project, I am making a chessboard in java.
there were certain limitations, being that we can't use images for any of the pawns. We needed to make a pawn out of multiple shapes.
For example I have a pawn made out of a circle and a…

zeta
- 1,113
- 3
- 15
- 24
3
votes
1 answer
Why isn't the panel painted?
CODE
import javax.swing.*;
import java.awt.*;
class tester {
public static void main(String args[]) {
JFrame fr = new JFrame();
JPanel p = new JPanel();
p.setBackground(Color.RED);
p.paintImmediately(20,20,500,500);
…

saplingPro
- 20,769
- 53
- 137
- 195
3
votes
4 answers
Drawing 2D graphics
I would like to make a simple game in Java that has already been designed. I just need a way to draw sprites, etc. It doesn't have to be anything complicated. What would be the first choice you'd recommend for this?
user2058002
3
votes
2 answers
Line2D decoration tips needed - Graphics2D
I have Line2D and Arc2D objects laid out on my JPanel by Graphics2D drawing. You can have a look a part of it on this question " How to make pixel perfect Line2D in - Graphics2D ". Now what I want to achieve is, I want to create two parallel lines…

TeaCupApp
- 11,316
- 18
- 70
- 150
3
votes
1 answer
JScrollPane shows graphics glitches on row header. How to avoid this?
I'm trying to use a JScrollPane with a column header and a row header.
On the rowheader, there is some text. When I scroll down the pane, some graphics artifacts appear on the rowheader. It's like the bottom line of pixels is repeated once and…

javier
- 133
- 1
- 2
- 5
3
votes
3 answers
Rotation and Scaling -- How to do both and get the right result?
I've got a set of Java2D calls that draw vectors on a graphics context. I'd like for the image to be doubled in size and then rotated 90 degrees.
I'm using the following code to do this:
Graphics2D g2 = // ... get graphics 2d somehow…

jsight
- 27,819
- 25
- 107
- 140
3
votes
4 answers
problems with AffineTransform
Hello I am new to affineTransform in java. I want to use it to shear some GUI I have to use later.
For now I just wanted to test a sample code but i cannot explain its output.
Here is the code
package main;
import java.awt.Color;
import…

coder
- 823
- 2
- 10
- 17
3
votes
2 answers
What to replace com.sun.image.codec.jpeg classes with?
I just started reading the O'Reilly book Java2D Graphics. The very first example is written using the proprietary com.sun classes, which are restricted, of course (I get the error "not accessible due to restriction on required library rt.jar").…

Nathan Hughes
- 94,330
- 19
- 181
- 276
3
votes
2 answers
How do i align this text correctly?
I wrote this polar clock today and i am almost finished exept i want to align my text inside the line similar to this. Does anyone know how to do this? Ive tried to use FontRenderContext and font metrics but i cant seem to get it to work. Here is…

Stas Jaro
- 4,747
- 5
- 31
- 53
3
votes
1 answer
More efficient way to blend pixels (semi-transparency)?
I'm working on drawing semi-transparent images on top of other images for a small 2d game. To currently blend the images I'm using the formula found here: https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
My implementation of this is as…

Zee Best
- 45
- 5
3
votes
3 answers
How to draw a two dimensional graphic at Java?
I have 2 different lists. Each of them holds x and y value pairs(they have both positive and negative values). How can I draw them on a 2D axis? I want to put points for every value and they will blue for first list and red for second list.
My…

kamaci
- 72,915
- 69
- 228
- 366
3
votes
2 answers
What are good resources to learn the Java 2D API?
I already know about the tutorials on Oracle's site. I would like something with more practical advice but also with a more systematic coverage of the fundamental concepts . I am not interested in Swing and GUI desktop application, more into batch…

Ludovico Fischer
- 1,602
- 11
- 11
3
votes
2 answers
Method to combine multiple affine transforms as if each was specified in un-transformed space
I'm looking for a way to combine affine transforms in such a way so that the effect is equivalent to using each transform to manipulate a shape in succession. The problem is that if I simply concatenate the transforms, then each successive…

CarlG
- 1,656
- 1
- 17
- 21
3
votes
4 answers
Not able to draw the circle, inspite of using a logical way
I tried to plot a circle using the java awt, what I get in output is just few small which are separated by much distance apart and doesn't look like a circle as a whole. Code is given below :
class DrawFrame extends JFrame {
int хс, yc, r, x,…

Vaibhav Singh
- 39
- 1
3
votes
1 answer
apply filter on selected Area of BufferedImage
i want apply some Filters on BufferedImage but don't apply these filters on whole
of bufferedImage , i need apply filter on Rectangle , ellipse , freehand selection of
BufferedImage.anybody have idea ?
thanks

mehdi shahdoost
- 1,469
- 5
- 17
- 27