Questions tagged [java-2d]

Java 2D is an API for drawing two-dimensional graphics using the Java programming language.

1076 questions
4
votes
3 answers

Rounding Inaccuracies When Combining Areas in Java?

I'm working with Areas in Java. My test program draws three random triangles and combines them to form one or more polygons. After the Areas are .add()ed together, I use PathIterator to trace the edges. Sometimes, however, the Area objects will not…
Peter
  • 4,021
  • 5
  • 37
  • 58
4
votes
1 answer

Stop Fullscreen Window from minimizing when JOptionPane.showMessageDialog?

The Code private MainApp() /* Extends JFrame */{ DisplayMode displayMode = new DisplayMode(800, 600, 16, 75); ScreenManager.setFullScreenWindow(displayMode, this); } The Problem Whenever I…
ApprenticeHacker
  • 21,351
  • 27
  • 103
  • 153
4
votes
4 answers

Horrendous Performance in a Simple Java2D App

I've just finished my entry for the 14th Ludum Dare 48-hours game making competition yesterday, and decided to do it in java using java2d for the graphics. I'm not that familiar with the API and haven't done a lot of graphics programming, but my…
4
votes
3 answers

Are actors the right tool to implement the messaging between a simple multiplayer game?

I'm thinking about using actors for a simple Asteroid-like game written in Scala and Java2D, which can be played by two players in a cooperative mode. Both players can control their own ship on a shared playing field, where asteroids float through…
soc
  • 27,983
  • 20
  • 111
  • 215
4
votes
2 answers

Swing Java2D on Java 11 and a modern iMac

A while back, I had written and had working a Zoom to Mouse Swing panel that handled highlighting, pan, mouse zoom, selection, etc. It was very nice. I went to play with it some more today, and it wasn't working. I was flummoxed. I knew I had a…
Will Hartung
  • 115,893
  • 19
  • 128
  • 203
4
votes
2 answers

Resizing an indexed image in Java without losing transparency

This is my function to resize images. The quality is not photoshop but it's acceptable. What's not acceptable is the behaviour on indexed png. We expect that if we scale down an image with a 256 colors palette with a transparent index we would get a…
Uberto
  • 2,712
  • 3
  • 25
  • 27
4
votes
4 answers

Can Java2D be as fast as LWJGL and JOGL?

I've heard that Java2D uses OpenGL behind the scenes to do it's rendering, and I've wondered if it's worth it to use JOGL and all it's native libraries for my program which is simply a 2D side scroller. I've heard that there are certain techniques…
HahaHortness
  • 1,570
  • 1
  • 15
  • 16
4
votes
1 answer

How to clip a Path2D?

Is there a way to clip a Path2D to an area / other path2D instance? Simple Example (I am looking for something that will work in the general case where paths may include quads or cubics and may or may not be singular): I have a line segment (0,10)…
tofarr
  • 7,682
  • 5
  • 22
  • 30
4
votes
1 answer

How to split a java 2dpath in equal parts

I'm trying to split a generic Shape into list of Points so we can move a certain sprite along the path depending on a certain percentage. Right now I can split the shape into multiple points: This was produced by the following code: shapeComp =…
Thijs
  • 41
  • 3
4
votes
1 answer

Smooth BufferImage edges

Is there a way to smooth the jagged edges of a transformed (translated and rotated) BufferedImage? A zoomed in view of a test image: (Note that this is not the actual BufferedImage that will be used, only for demonstrating here). Bilinear…
H3katonkheir
  • 664
  • 1
  • 7
  • 21
4
votes
3 answers

"Zoom" text to be as big as possible within constraints/box

First problem: You have 400 pixels width to go on, and need to fit some text within that constraint as large as possible (thus, the text shall use that amount of space). Throw in a new constraint: If the text is just "A", then it shall not zoom this…
stolsvik
  • 5,253
  • 7
  • 43
  • 52
4
votes
7 answers

Java: Friendlier way to get an instance of FontMetrics

Is there a friendlier way to get an instance of FontMetrics than FontMetrics fm = Graphics.getFontMetrics(Font); I hate this way because of the following example: If you want to create in a game a menu and you want all the menuitems in the center…
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
4
votes
1 answer

How to save current state of graphics on JPanel

I have a program that lets the user add rectangles and circles to JPanel using Graphics. What I want to be able to do is save the current state of the current JPanel (i.e. all of the shapes and their locations) into a file and be able to load that…
Harry
  • 772
  • 10
  • 32
4
votes
1 answer

Appending circle shape to Path2D

So, to append a rectangle to a Path, you can do this Path2D rect = new Path2D.Double(); rect.append(new Rectangle(10, 10, 100, 10), true); What I want to do is something like this: Path2D circ = new Path2D.Double(); circ.append(new…
nick
  • 309
  • 1
  • 5
  • 15
4
votes
1 answer

Need help understanding the affect of two java gui-related system properties

I had a problem envolving a mixing of lightweight and heavyweight components in java. Weird swing heavyweight & lightweight mixing problem A solution that was suggested to me (outside stackoverflow) was to set the system properties…
Yoav Schwartz
  • 678
  • 1
  • 8
  • 18