Questions tagged [graphics2d]

Graphics2D is the part of the Java 2D API related to two-dimensional graphics, text, and imaging capabilities. Unlike the older Graphics class, Graphics2D supports coordinate transforms. It also gives better control over geometry, colors and text layout.

The java.awt.Graphics2D Java class is part of the Abstract Windowing Toolkit () library and was first included in Java Standard Edition version 1.4. It supersedes the java.awt.Graphics class from earlier Java versions. Graphics and Graphics2D are subsequently used by .

Unlike Graphics, Graphics2D supports coordinate transforms, uses floats rather than ints for better control over geometry, also has improved color management and text layout control. Many system library methods that return, expect or receive a Graphics object are actually working with Graphics2D object that can be casted:

@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    ....
}

This allows some restricted Java implementations (like early versions of GNU Classpath) to opt not to implement Graphics2D and still formally support the complete API.

Graphics2D is used to display shapes, text and images in user interfaces components and includes methods for settings the style and transformations of the graphics output, and for controlling the rendering of the graphics.

1667 questions
0
votes
1 answer

Graphics2D does not pull in values from class variables

I'm trying to create a Graphical Circle Calculator program that allows the user to input the diameter of a circle, with the resulting output showing a representation of the circle in a frame along with the radius, circumference, and diameter. I used…
qkflies
  • 31
  • 2
  • 6
0
votes
1 answer

Layouting components in a JPanel

I have 3 JPanels wich have no Components and have just Graphics2D pictures on them. The positioning of pictures wasn't a problem. But i have a problem trying to put them in necessary order on a JFrame. This is the code I am using: setLayout(new…
Evgeniy
  • 3
  • 2
0
votes
1 answer

Swing JScrollPane Overflow

I have a Java Swing application with lots of custom components. The layout is a large JScrollPane that contains a JPanel, which has several panels in a BoxLayout from left to right. In the image below, the code panel contains a JScrollPane that…
alistair
  • 1,164
  • 10
  • 27
0
votes
1 answer

Java Applet dragging issue

Picture: http://gyazo.com/e3bd39a4a967f4cd331f731fd6920702 The red cross on the picture represents the mouse position. When I drag my box it keeps going grabbing the box in the upper left corner. How can I change this piece of code so that it will…
user2898147
0
votes
1 answer

Graphics2D is incapable of alpha?

I am implementing layers in a 2D engine of mine and I would like layers to be stackable, and I would also like a feature to 'cut holes' in layers - this means using alpha. However when writing it standalone I can't seem to get anything to use true…
Lee Fogg
  • 775
  • 6
  • 22
0
votes
1 answer

Calculate distance between point and area using Java Graphics2D

I'm trying to build an automated guided vehicle simulator using fuzzy logic in Java, but I stuck on this. I'd like to calculate distance between point and area using Graphics2D. I know point location, angle and color of the area. It looks like this:…
Senoy
  • 1
  • 2
0
votes
2 answers

Draw an Image on Foreground

I try to draw a .PNG Image using graphic2D.drawImage() method. And I make it right, but I've one JPanel on my Frame, and when I draw my image, it appears in background. I want it to appear on the foreground, and obviously in front of my JPanel.
Neewd
  • 93
  • 2
  • 13
0
votes
1 answer

With Java's graphics shape drawing operations, is there an easy way to give the shapes transparency gradients and blurry edges?

What I would like is to give circles a fill color with a gradient that starts from the middle and then as it moves out to the edges becomes progressively more transparent, giving a blur effect. What is the simplest way of doing this?
Alex Lorimer
  • 477
  • 5
  • 9
0
votes
1 answer

java - paint on top of nested components

So I am working on a Java game using a combination of swing components, and Graphics2D. I have an AbstractLevelView class which contains all of the elements of the game inside. This LevelView component uses a BorderLayout to display a context bar on…
zalpha314
  • 1,444
  • 4
  • 19
  • 34
0
votes
1 answer

Zoom an Image after ActionListener

I try to create an Image View Program and have a problem in Java Image's zoom in and zoom out :D I create a JPanel and using BufferedImage to display an image in my computer. After clicking a button, it should be zoom . But the problem in here that,…
Lup
  • 197
  • 1
  • 1
  • 7
0
votes
1 answer

How do you manipulate graphics without a graphics api?

Is there a way to do basic graphics manipulation in any existing language without relying on a graphics api such as opengl or directx? What I want to do essentially is do something similar to the way classical machine languages manipulated…
邪悪歌
  • 41
  • 3
0
votes
0 answers

Double Buffering image in JFrame with other swing controls

I have a JFrame with an JLabel that houses an ImageIcon containing a BufferedImage. The BufferedImage's graphis are drawn on with several different graphics calls, such as drawOval(), drawRectangle(), etc, with many drawn shapes on it. As time…
Stealth Rabbi
  • 10,156
  • 22
  • 100
  • 176
0
votes
1 answer

Coloring a certain part inside a curve drawing

I'm drawing a bird.. or more specifically Zapdos from Pokemon. I want to know what kind of code I can use in coloring inside the beak and outside the beak. Although I'm kind of planning to try coloring the whole part with ovals... but what specific…
Louie
  • 13
  • 1
  • 4
0
votes
1 answer

Only half of my drawing using drawPolygon is showing up

This is the bit of code that does all of the drawing, but it's only drawing half of the arrow. When it's a vertical arrow (North or South), it cuts off the left side, and when it's horizontal (East or West) it cuts of the top, both centered right at…
0
votes
1 answer

How does Graphics2D handle subpixel accuracy?

Running in circles in grepcode trying to find the source for how a rotated image is drawn with subpixel accuracy. I am specifically interested in the method drawImage(Image img, AffineTransform xform, ImageObserver obs) which handles rotations but…
arynaq
  • 6,710
  • 9
  • 44
  • 74