Java 2D is an API for drawing two-dimensional graphics using the Java programming language.
Questions tagged [java-2d]
1076 questions
6
votes
1 answer
How to render text using FRACTIONALMETRICS in Java 7
I have a desktop Java application i'm working on and have been using JDK 6 for development via IDE. I use the rendering hint VALUE_FRACTIONALMETRICS_ON along with other hints to better render text in JLabels. These hints work beautifully on JVM 1.6…

Sammy Guergachi
- 1,986
- 4
- 26
- 52
6
votes
5 answers
Drawing a nice circle in Java
I'm using Java Graphics and I keep getting "ugly" circles.
Here's what my Java program makes
And here's the same thing being made in Matlab
I think it is clear that the Java one is not as "nice" looking as the Matlab one, particularly on the…

CodeGuy
- 28,427
- 76
- 200
- 317
6
votes
2 answers
Creating and drawing huge (Buffered) images in Java
I'm working on an application which draws out a matrix - using Java 2D - which can become quite large, for example 30000 x 30000 pixels.
At this moment I've experimented a bit with BufferedImage but creating such a huge BufferedImage causes out of…

RBaarda
- 558
- 3
- 10
6
votes
1 answer
Java create anaglyph (red/blue image)
I'm writing a Java game engine (http://victoryengine.org) and I've been experimenting with generating "3d" images with depth that you can see with those red/blue glasses. I'm using Java2D for graphics.
I've created something that works, but is very…

Bart van Heukelom
- 43,244
- 59
- 186
- 301
5
votes
2 answers
How to draw on a JLabel?
I want to use the 2D Java API to draw on a JLabel that already has an image on it and then save the resulting edited picture.
I can't find any tutorials on this specific subject, does anyone have any code or references that show how to do it?

James MV
- 8,569
- 17
- 65
- 96
5
votes
3 answers
Component painting outside custom border
In this custom border class, I define a RoundRectangle2D shape. This object is used to paint the border. Unfortunately, since the paint method of a JComponent invokes paintComponent before paintBorder, setting the Graphics clip to the…

mre
- 43,520
- 33
- 120
- 170
5
votes
2 answers
Why doesn't the Graphics' draw method respect stroke attributes?
I want to create a custom border with rounded corners.
Code -
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import…

mre
- 43,520
- 33
- 120
- 170
5
votes
3 answers
Java: How to drawString() from ascender line
I am displaying some graphics text on Screen by using the drawString(. . .) function of Java2D Library.
Refering to the figure in this article i want my string to be drawn from Ascender Line rather than BaseLine. In simple words is there any way to…

Jame
- 21,150
- 37
- 80
- 107
5
votes
3 answers
Java2D/Swing: Rendering a component with text anti aliasing to a BufferedImage
I would like to render a Java Swing component, e.g. a JButton, which I also put on a JFrame, to a BufferedImage. This works in general, but with a major drawback: Text anti aliasing, especially "LCD" anti aliasing mode, is not working when rendering…

It's Leto
- 968
- 4
- 17
- 25
5
votes
4 answers
How to animate Rectangle on a Path2D object in Graphics2D context
I have just started learning basics about Graphics2D class, So far I am able to draw different objects and implements ActionListener to actually move them on screen by onKeyPress. So far so good, While I thought of doing something more complicated.…

TeaCupApp
- 11,316
- 18
- 70
- 150
5
votes
2 answers
How do I create and distribute diagonal stripes on a rectangle?
I would like to be able to create bar charts with JFreeChart that looks similar to the following picture.
It is a very basic mono-colored bar chart, but with one "fancy" detail: the diagonal stripes. I was thinking that this could be made possible…

oligofren
- 20,744
- 16
- 93
- 180
5
votes
1 answer
Java2D: BufferedImage not accelerated on Ubuntu
We are currently developing a game in Java using the Java2D API and are experiencing some strange performance issues when running it in an Ubuntu environment.
Our frame rate drops from an average of 62fps on Windows and Mac systems to about 10fps on…

Scott
- 51
- 1
5
votes
2 answers
Which component to subclass to draw in Java2D (for a 2D game)
I have created my own canvas that has been extended from the JPanel, however I have noticed that w/ the content and so forth, that all of the sudden my FPS took a hit. I am following the swing rules from Filthy Rich Clients, by using paintComponent,…

abc123
- 71
- 3
5
votes
2 answers
How to go about creating a race track game?
i am planning to make racing game in android.I have created many applications in different mobile technology. but i am pretty much beginner for game application. So my question is how can i make race track in android? How should i show that car is…

Vivart
- 14,900
- 6
- 36
- 74
5
votes
0 answers
Why is Java2D faster on a (slow) integrated GPU compared to a (fast) dedicated GPU?
I am trying to optimize the performance of an application by switching from Java2D to OpenGL (LWJGL). I wrote myself some benchmarks to see the performance difference between those two and was happy with the result in the beginning. However when I…

Wolf
- 892
- 2
- 8
- 22