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

moveTo method using split/replace

458.41016 425.70843 427.74316 392.55343 403.93516 370.91243 399.48516 366.83843 398.54916 368.02743 397.41516 372.27043 394.75116 382.25643 392.96616 392.69543 391.09516 402.03043 390.35916 405.62343 389.79116 406.92443 392.62616 409.52743…
a14
  • 31
  • 15
0
votes
0 answers

Transparent dragging component image as the drag icon in Swing

How can I set a quite large drag icon made by transparent dragging component image. So the user sees what has selected for dragging while dragging. It'd better that the image has a graded transparent level so the bottom right of the component image…
puk
  • 193
  • 2
  • 13
0
votes
1 answer

Graphics2D reset Screen?

I have a Game Tutorial that I followed, that paints String's on the Screen using Graphics2D. It works like a star, but the only problem is that I don't undertstand why. I call draw(graphics) in a game loop and it works fine. I use an int, named…
SirTrashyton
  • 173
  • 2
  • 3
  • 12
0
votes
1 answer

Java 7 - Graphics2D.setFont() and Graphics2D.setColor() is being overridden by defaults when Printing.

I have a program that draws to the a panel and also prints. When drawing to the Canvas the renderer produces the correct output. However when drawing to the print method the font is overridden with a default font. Please see below two images…
chin-apse
  • 25
  • 5
0
votes
1 answer

JAVA - How to convert sexagesimal and plot as a line?

What I am hoping to figure out is how you would convert the following sexagesimal type of direction: N. 00 deg. 23' 44" E. 290.40 feet, and then plot a draw a line based on the bearing, direction and distance from that. You would basically have a…
porterhaus
  • 439
  • 2
  • 5
  • 17
0
votes
1 answer

Buffer Strategy with Per-pixel Transparency

Viewing this I thought I understood per-pixel transparency, however when replacing the JPanel with a Canvas, then replacing the rendering method with a buffer strategy, I cannot obtain per-pixel transparency. window.setBackground(new…
David
  • 557
  • 4
  • 15
0
votes
0 answers

Hangman Graphics

I'm having trouble getting the graphics to show up with my hangman program. This is the code for my engine class: public static void main(String[] args) { //hangman viewer stuff …
user2963365
  • 81
  • 1
  • 3
  • 8
0
votes
1 answer

Paint component over background

I have a little problem drawing some images. I am using a JDialog to display the background and a separated class to display the cards (using sprites). The background displays well but the JPanel don't. Here is my code : public Main(java.awt.Frame…
Kaymaz
  • 454
  • 8
  • 23
0
votes
2 answers

Painting different non-rectangle polygons on semi-transparent JPanel causes ugly edges

I'm working on a custom menu for a game and a problem occured to me by trying to draw the components. The idea is, to have either a picture or a video running in the background with a panel on top of it containing some custom menu-items. The panel…
BenGe89
  • 141
  • 1
  • 7
0
votes
1 answer

Issues with loading Images into a Graphics2D

I'm trying to load Images into this program and it won't work and I've played around to make sure that I had the directories right and everything, but now I'm kinda at a lost. The draw function called in by the PersonFront class works fine, but not…
CJ Jacobs
  • 299
  • 1
  • 16
0
votes
2 answers

Java Swing resize BorderLayout.CENTER

As the title says, can I redefine the height and width of Java's BorderLayout.CENTER? I plan to use Graphics2D to draw to this area but I won't always know ahead of time how big it should be to fit everything in. Draw class (declared inside my Main…
Iain
  • 1,724
  • 6
  • 23
  • 39
0
votes
1 answer

java JLabel does not repaint resized label properly after 90 degree rotation

i have a use case like after adding JLabelComponent to pallet which i have to resize to custom level(re sizing bcz data is very large ) the added label component.Once i am done with re-sizing setting the component.setBounds all the coordinates.…
0
votes
2 answers

Arranging squares by coordinates

I do a project in Java. For the project I have to arrange squares(a class I created, I will give the code at the end) according to their coordinates(the left up corner of the window was chosen as 0,0). Right now the squares are in an ArrayList. I…
TJR
  • 454
  • 8
  • 24
0
votes
1 answer

Jittery movement with Graphics2D and double buffer

I´m having some problems with a small game I´m developing. although I´m using double buffer and was able to get rid of flickering, the movement still looks somewhat jittery and not fluid. I know it can be caused by increasing the movement in big…
0
votes
1 answer

produce a plot with multiple points in a JPanel

I do not have much familiar with graphics in Java, sorry. However, this is what I'm trying to do. I want to be able draw a couple of points on a canvas (JPanel here), and be able to redraw the points everytime the method (drawPoints) is invoked with…
apil.tamang
  • 2,545
  • 7
  • 29
  • 40