Java 2D is an API for drawing two-dimensional graphics using the Java programming language.
Questions tagged [java-2d]
1076 questions
0
votes
1 answer
Repaint isn't calling draw
I'm trying to call a draw function using repaint inside a while loop. I'm not very familiar with how exactly repaint works.
The research I've done on repaint says it waits for the actions to be completed before it calls the draw method which may be…

Micah H.
- 97
- 12
0
votes
1 answer
how to get resolution (PPI) of an image
Possible Duplicate:
How to define DPi for a new JPG image?
Is there a way to get a resolution (pixels per inch) of an image in Java? Either with Native APIs or third party libraries. I don't just want the height and width of an image but actually…

Omnipresent
- 29,434
- 47
- 142
- 186
0
votes
1 answer
Java draw line with textures
I'm trying to figure this out with no success. I can draw rectangles with a texture but how could I draw a line of say 4 pixels wide at an angle using a texture? Example like a / or \?

sproketboy
- 8,967
- 18
- 65
- 95
0
votes
3 answers
Graphics - How do I use the method create(int x, int y, int width, int height) and translate(int x, int y)?
I was trying to do my computer science homework but I am stuck as I was trying to use the following methods.
public Graphics create(int x,int y,int width,int height)
That Creates a new Graphics object based on this Graphics object, but with a new…

Kingfu Chow
- 19
- 2
- 4
0
votes
2 answers
How to update java canvas dynamically?
Problem: I am trying to update the canvas with new painting objects based on user action. The canvas dosent get updated.
What i have done: The user interacts with the DnD action,The transferrable object reaches the canvas, Calls an update graphics…

Balaram26
- 1,349
- 3
- 15
- 32
0
votes
3 answers
Draggable rectangles in Java 2D
Possible Duplicate:
how to drag object
I need to draw some UML components (classes, packages etc) using Java 2D and then be able to drag them around. Is there a way to do this? I mean, to make a shape "draggable"?

nicolasSiandro
- 44
- 4
0
votes
1 answer
Merge two images in java
I have two images, one base image (background image) and the second is an overlay image. The base image is 180*269 pixels and the overlay image is 1000*2250 pixels.
I have to place the overlay image with specified points. This is almost like virtual…

user1920724
- 21
- 1
- 3
0
votes
2 answers
JPanel inside PopupMenu
Is there a way to render graphics like JPanel in a PopupMenu (with TrayIcon)? I know it's possible by using JPopupMenu but I do not like that the popup doesn't close if I click outside of it (and the icon does not get highlighted as with…

Niclas Larsson
- 1,317
- 8
- 13
0
votes
3 answers
get String from Java Graphics instance
I have some code snippet that goes like below
:
Graphics g; // Java Graphics class
g.drawString("text", x, y); // x, y for coordinate info, "text" is now an image object
:
Can I get "text" back into a String from the Graphics…

Calia Kim
- 65
- 14
0
votes
1 answer
ImageIO.read(FileInputStream) returns null when reading a very large image
I need to read an image, resize it and then save it.
However, when reading a very large image, ImageIO#read() returns null.
FileInputStream f = new FileInputStream(imagePath);
image = ImageIO.read(f);
How is this caused and how can I solve it?

azade zarabiyan
- 1
- 1
0
votes
2 answers
Specify line spacing while appending text on Image
I am Appending Text on images. How to specify the Line spacing between two lines while appending on the text on the image?
EDIT:- I want to Control Line Height of the text.
final BufferedImage image = ImageIO.read(new File(Background));
Graphics g =…

Code Hungry
- 3,930
- 22
- 67
- 95
0
votes
1 answer
multi threaded graphics using a timer?
My lecturer gave me an assignment asking for a multi threaded graphics program where a ball bounces around a jframe. He wanted each ball to have its own thread. Upon marking he told me that a timer is multi threaded and this is the best way to do…

Harry Martland
- 604
- 2
- 14
- 26
0
votes
1 answer
Line2D and a JComponent intersection points and affine transformation
Ok
I have the line and the component. The component itself is a JPanel. I draw shapes inside it. And adding the shape to the container. This shape can be any polygon. And drawing a curved line (this can be Line2D, CubicCurve2D or QuadCurve2D) in a…
user1326628
0
votes
0 answers
Painting JLabels on a JPanel
I have a JPanel set up, and I have JLabels acting as pseudo-buttons placed on top of the JPanel (with jPanel.add(jLabel)). I want to animate the JPanel without affecting the JLabels, but every time I repaint the JPanel, the labels disappear. (I…

Shahmeer Navid
- 566
- 4
- 10
- 18
0
votes
1 answer
Making font size smaller than 1 Java GUI
I want to label my hashmarks in my grid for my graph, however when I use even font size 1 it is way to big! Is there a way to make a font size smaller than 1? Am I missing something with how I'm coding it?
Here's the code which generates the grid…

Evan Hirtenfeld
- 43
- 1
- 5