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
2 answers

Line not appearing on JDesktopPane

I want to draw line between two JPanels but line is not appearing on layeredPane. This is what i have done please go through it, compilable.Do try and correct this code. I have tried on drawing lines on Internal frames this way but it is not working…
Asd
  • 103
  • 2
  • 12
0
votes
2 answers

Drawing line between two JPanels

I want to draw lines between two JPanels ; please verify my code as its giving an NULL pointer Exception at "g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);" Code:: Draw(JPanel one , JPanel two) { //Draw…
Asd
  • 103
  • 2
  • 12
0
votes
1 answer

Graphics2D does PostModern

In the following code changing fill to draw produces unexpected results. The attached image demonstrates the undesired but much appreciated postmodern effect caused by drawing the red and green rectangles. The affine transform should not be part of…
necromancer
  • 23,916
  • 22
  • 68
  • 115
0
votes
2 answers

Rotating graphics

I am trying to make a bullet class. When it is called it will get a direction and an initial position. The problem is the direction is not working it only goes up no matter what I set as the direction. Please Help. Thanks in advance public class…
user2378547
  • 1
  • 1
  • 1
0
votes
1 answer

Java fillPolygon(Polygon p) doesn't work when p is circle contour?

I have here a situation, I can't handle by myself. I'd like to draw and fill Polygon onto JPanel. I have written Moore-Neighbor Tracing algorithm…
Kousalik
  • 3,111
  • 3
  • 24
  • 46
0
votes
1 answer

Scale an image with Graphics2D

In a game that I am making I want the power ups to be airdrops. I have a image of a crate that I want to be draw bigger than I have drawn it. Then I want the image to become progressively smaller with times so that it looks like it's dropped from…
user2327513
0
votes
2 answers

C# Equivalent to java's Graphics2D

I've recently started about thinking about making a 2D game engine in C# from scratch. Now, I've wondered: In java, I'd use the java.awt.Graphics2d and java.awt.Container classes. What would you suggest me to use in C#? Apparently, google couldn't…
Jan Berktold
  • 976
  • 1
  • 11
  • 33
0
votes
2 answers

Rotating an Object

I know how to rotate the image but how would I rotate the acctual Objet? I can't use g2d.rotate(); because I have multiple things drawn with the paint() method and I only wan't one of the to rotate.
user2327513
0
votes
2 answers

How to Fill a path with a pattern in Quartz

I have created a view and in my draw rect method I create paths depending on what a user does with sliders. Using standard colors , everything works and looks very nice. I am trying to follow a code snippet from apple that shows how to draw patterns…
Miek
  • 1,127
  • 4
  • 20
  • 35
0
votes
1 answer

Java rescaling an image creating half white half grey image

I am having a problem with the Grapics2D API, I am trying to re-size an image but instead of getting the smaller image its showing a half white and half grey area. what am I doing wrong? I tried with and without render hints and it didn't work, or…
user1718720
0
votes
1 answer

BufferStrategy not scaling Graphics2D

I am currently trying to program a simple platform game. I would like to scale the graphics up by a factor of 2/4/whatever so that I can get an old-school look and feel from the game. However, when I call scale on my Graphics2D instance, nothing…
dave
  • 1,607
  • 3
  • 16
  • 20
0
votes
1 answer

Mandelbrot set in java doesn't calculate correctly

I'm still relatively new to Java. I've been working on a program to display the mandelbrot set. My current code generates an image that is close, but not quite the mandelbrot set. This is my generation code: private void generateMap () { //…
leopardGeckos
  • 91
  • 2
  • 8
0
votes
1 answer

Drawing Rounded Rectangle

I am wanting to turn the example below in a figure that uses RoundedRectangles instead of normal rectangles, I know there are possibilities with the clipping frame. But I don't really know how they would apply to my current situation, as I am not…
skiwi
  • 66,971
  • 31
  • 131
  • 216
0
votes
1 answer

Java How do you manage layers when drawing?

I am using Java's AWT package to draw using Graphics2D and a BufferStrategy on a Canvas. The Canvas is placed onto a JFrame. When I place Entities from my game onto the canvas and draw them they seem to be rendered in a seemingly random order. I…
Zach Sugano
  • 1,567
  • 5
  • 22
  • 41
0
votes
1 answer

superscripts does not show properly on an image created by itext on pdf

I have a very confusing problem about unicode support in the generated pie chart in my pdf. Here is what I have: I am generating pie chart (with jfreechart library) that need to add superscripts on the title of the pie chart. I tested and I know…
pms
  • 944
  • 12
  • 28
1 2 3
99
100