1,083 questions
1
vote
2
answers
103
views
How can I replicate this image using Java2d?
I'm trying to replicate this image using java2d, and I've almost done it, but there's a slight difference.
In the original image, there are 4 circles overlapping in the center, but in my output there'...
2
votes
0
answers
102
views
Why does changing the FPS limit affect Graphics2D rendering performance?
I'm working with an AWT Canvas with a triple buffered BufferStrategy. The application runs a loop that renders the screen with a set maximum FPS. Specifically I'm drawing multiple characters on screen ...
3
votes
0
answers
161
views
Why does Java FontMetrics return wrong string bounds (specially height) for some .ttf?
I’m generating text images for different .ttf fonts in a method using Java2D, most of the fonts it works fine. The issue is with some fonts it return wrong "Y" value.
// params
File ...
3
votes
2
answers
109
views
Java2D Compositing - Incorrect Java/Oracle Documentation
I am going to improve and supplement this question but maybe I'm right and someone knowing can help shortcut this question/issue... Isn't the following web documentation by Oracle incorrect? https://...
1
vote
1
answer
87
views
When running java against a jar java2d is not being found? [duplicate]
I am using client host commands from powershell to launch a Oracle forms FSAL via the following command:
java -jar "fsal jar location" -url "url"
This command works except there ...
0
votes
1
answer
68
views
Java Graphics - Drawing multiple images next to each other creates empty lines
I am trying to draw the map of my game, it has tiles object with x & y location. The image of the tiles are hold by 1 class, and I resize them once I finished zooming.
I want to draw the images ...
0
votes
1
answer
115
views
How to include trailing space in text measurements using TextLayout?
I am using the java.awt.font.TextLayout class to measure the bounds of a text string. In this measurement I need to include any trailing whitespace. However it seems that by default, TextLayout ...
1
vote
1
answer
86
views
Clojure2d: drawing on the canvas silently fails if it has been resized
The following code successfully displays a blank canvas with a small red square:
(ns test-rect
(:require [clojure2d.core :as c2d])
(:require '[clojure2d.extra.utils :refer [show-image]]))
(c2d/...
0
votes
1
answer
421
views
Is it possible to render image from a PDF using PDFBox in a Spring Boot Native application?
I am trying to figure out how to use PDFBox (2.0.30) to render image from a PDF document in a native application based on Spring Boot (3.2.1).
PDF generation works fine, but image rendering fails. ...
1
vote
0
answers
37
views
Create Two Row image from Text in Java
I already have a working API in java that takes text in request, and creates a PNG image from this text using custom fonts and returns a BASE64 encoded data of the image.
Now, I need to modify this ...
0
votes
1
answer
117
views
Java 2D graphics backgammon table (algorithm question)
My problem is I need to use only one drawLine. I couldn't figure out how am I supposed to make changes at the same time in x and y while not messing with one and another. I can't use a rectangle.
int ...
0
votes
1
answer
48
views
Finding a square in a blank image
Let's say I have a JPG image that's completely white except for a green filled in square that's placed randomly. The square has equal side lengths of between 20 and 30 pixels.
I'd like to write a Java ...
0
votes
1
answer
248
views
Java Swing 2D - Draw many small stars quickly
I'm trying to make a game, and in the game is a background that has many small stars that slowly travel from right to left. With a full screen I may have 170 stars being drawn each frame. The ...
1
vote
0
answers
139
views
How to rotate and scale a Rectangle2D in java and return a Rectangle2D (not a Shape or Path2D)
Is it possible to scale or rotate a Rectangle2D and get a new transformed Rectangle2D?
I know it is possible to get a Shape or Path2D, but how to get a new Rectangle2D from a specific Affine transform ...
-1
votes
1
answer
62
views
Unable to drawimage on null layout swing
I want to draw some images on screen alongside some JButtons placed in different places of the screen. However whenever I have setLayout(null); the images do not show up on screen. If i don't set it ...
1
vote
1
answer
160
views
How do I make a top down view with the ability to rotate with built in java graphics?
I'm trying to make a racing game with the top down view on a static player in the middle of the screen, so instead of moving the player through the map, the map would move around the player. Since it'...
0
votes
0
answers
73
views
Click inside a figure
How can I know if the user has clicked inside a Pentagon and a Ellipse? I was able to create a method for Circle, Triangle and Rect, but I got stucked in those two figures.
Rect:
public boolean ...
0
votes
1
answer
426
views
How to combine rectangles?
I am working with the Java Swing library. I have two rectangles of the same width and height and the same coordinates. I want to combine them into one so I can get a cross. How can I achieve it?
0
votes
1
answer
210
views
Create Polygon that update after the insertion of every point
I am having a problem with a school project in Which I create a Polygon that when I insert points the polygon update after the insertion of every point.
For example
My program:
The result I want:
...
0
votes
0
answers
166
views
Trying to make a rainbow using 2 arcs and filling the lines between with the FXgraphics2D drawArc and drawLine functions
Trying to make a rainbow using 2 arcs and filling the lines between with the FXgraphics2D drawArc and drawLine functions. Its not working as expected. The assignment is to make a rainbow starting and ...
1
vote
1
answer
51
views
Java2D method call without class
I just started to learn Java and tried to draw some rectangles.
I have run this example and can't understand one thing:
class ShapesDemo2D has a constructor:
public void init() {
//Initialize ...
0
votes
1
answer
909
views
Drawing onto a Java2D Path using several Transforms
I have a fairly complex list of short line segments that taken together form a line.
I'd like to take this line and draw it 4 times along the 4 edges of a polygon. Obviously, for each side of the ...
-1
votes
1
answer
675
views
Java : read an image inside a binary file (or maybe more generally, from a stream)
I am making a java program that reads a binary file, which contains multiple images (in PNG format), and some binary data.
How can i load the images (specifically, as java.awt.Image's) ? So far the ...
1
vote
1
answer
89
views
How to create a new Shape out of two Ovals in AWT?
For my program, I want to have two ovals overlap and then create a new shape out of the overlapped area. So that I can later combine the resulting shape again with another shape.
In the end, I want to ...
1
vote
1
answer
225
views
How can I fill a java Shape in OpenGL
Well, lets say I have the Shape of an O and I want to render it.
Now my current rendering code is this:
public void fill(Shape shape, float xOffset, float yOffset) {
AffineTransform transform ...
1
vote
0
answers
190
views
Do Java Fonts work with all unicode code points?
I am trying to read all glyphs the font has available, in my case 547. Here's what I've done so far:
private static String getCharacters(Font font) {
final int glyphs = font.getNumGlyphs();...
0
votes
1
answer
1k
views
How to determine the java2d uiscale factor?
I know you can set the factor via -Dsun.java2d.uiScale=2 but what if I want to let the System choose the Value, how do I get the value set? Where is it saved?
0
votes
1
answer
1k
views
Changing a shape and a colour after a click (GUI, Java)
I'm just learning how GUI works and I wanted to write a code where following happens:
firstly we see red rectangle
after a click it changes into a circle in gradient (I picked orange and pink) + the ...
0
votes
1
answer
410
views
Detecting a mouse hover over an object that is not a JComponent
As the title states, I am trying to detect a mouse hover over an object that is not a JComponent.
Right now I have a window with a green JPanel. When you left-click on this JPanel you create a point.
...
0
votes
1
answer
4k
views
Initialization of 2D Array in Java?
I've a little confusion, when we declare & initialize a 2D array in java like given below
int arr[][]={{1,2,3,4},{4,3,2,1}};
This work correct, but when do do the above action like given below
...
0
votes
2
answers
166
views
How to determine screen geometry
I have the following code.
import java.awt.*;
public class ShowScreenSize {
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
...
4
votes
2
answers
686
views
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 ...
0
votes
0
answers
344
views
Java 2d painting problem in JavaFX SwingNode
I have a java application with old vector graphics editor written in pure Java Swing and Java2D.
Now I want to migrate the whole application to Javafx toolkit, except graphics editor. Graphics editor ...
1
vote
1
answer
294
views
Start angle and extent values using Java's Arc2D give unexpected results
I am trying to understand the use of Java's Arc2D. Don't know how to calculate the start angle and extent when creating an arc out of an ellipse (not a circle). I want an arc of an ellipse with ry = 2 ...
0
votes
1
answer
96
views
Text rendering deformed upon updating MacOS to Catalina
The Java SE 8 app I'm developing needs to run on Win10 and MacOS, and I'm using a Font (Ariel) that renders well on both platforms:
Here is an example of how it normally looks (MacOS 10.13):
I was ...
0
votes
0
answers
186
views
How Graphics/Graphics2D are implemented?
As seen in the Javadoc, most of the methods on rendering are abstract.
How are they implemented?
How do Java2D draw a square on my screen? (the answer I'm looking for is not "via 2 triangles&...
0
votes
1
answer
190
views
Draw circle with lines in it and check if mouse is inside the circle- Java Graphics- Geometry
Using Java graphics, I tried to draw a circle, draw lines inside it, then check if the mouse is inside the circle and print the position of the mouse.
The lines I draw exceed the circle and when I ...
0
votes
2
answers
113
views
Java 2D - JLabel only partially painted inside JList
I'm experimenting with 2D painting in Swing, and I'd like to paint a JLabel in the middle of an empty JList.
Thus I came up with:
public class MyJList<T> extends JList<T> {
private final ...
0
votes
0
answers
166
views
Gradually incrementing stroke width in java
I have to draw the figure on the link in java as an assignment.The assignment
So far I have been able to draw the first arc using CubicCurve2D, as seen on the picture on the second link, but now I ...
0
votes
0
answers
41
views
How to not to paint a certain part of background image?
Code to paint a picture to a panel:
public class MyDraw extends JPanel {
background = new ImageIcon("src/background.jpg").getImage();
@Override
protected void paintComponent(Graphics ...
0
votes
1
answer
69
views
Curved Path2D becomes straight when increasing stroke size
I have this strange problem with Java2D. I have a Path2D.Double that I want to draw, but depending on the stroke size, all segments are drawn correctly (curved) but when the stroke size is greater or ...
2
votes
0
answers
318
views
Moving a square on Y-axis in JPanel [closed]
I was trying to move a square on Y-axis with the help of buttons up "upp" and down "ner". But I am not really good at JFrame functions so I need help.
Edit: Fix the issue by ...
-1
votes
2
answers
111
views
Java 2D rotate BufferedImage
This question was answered many time but I still can't apply it to my situation.
I want to rotate image on 90 degrees clockwise.
I'm currently having following code:
private void writeImage(...
0
votes
1
answer
388
views
Java canvas doesn't update at all
I'm trying to make a Brick Breaker game where the ball which is initially on the paddle(referred to as BAR in the code below) is launched with a speed(approx 100) in some random direction, if it hits ...
1
vote
1
answer
65
views
Rotating a picture causes rotation of other pictures in a loop g2d.rotate
I'm trying to make a game like Tank Trouble.
The problem is that when I'm trying to rotate and draw a tank picture, all other tanks pictures will be rotated.
Here is my code:
// draw tanks
ArrayList&...
0
votes
1
answer
418
views
How to draw polyline with negative coordinates in java [closed]
I want to draw polyline with positive and negative coordinates.
e.g.
125,66
126,62
-128,59
-127,55
-125,51
-124,47
-122,43
-121,40
-119,38
-118,36
These are the sample coordinate to draw the ...
0
votes
0
answers
54
views
Correctly Sizing a Canvas inside a JFrame
my current project is a small desktop application in Java that functions like a room decorator similar to the IKEA software that lets you plan out your room before you go and buy furniture. When I ...
0
votes
0
answers
99
views
Why is my GPU over 75°C when I run an undemanding Java game?
I have recently moved to Linux Mint 19.3 and run my Java game. In one hand I have FPS that's higher than on Windows 10 (~150 FPS VS ~4000 FPS). But in another hand my game is very lag. And I don't ...
-1
votes
1
answer
498
views
Why is an image displayed with Graphics.drawImage() in Java not like I drew it
I have BufferedImage that stores .png image (320 x 240) and I draw it on Сanvas with Graphics.drawImage(). But if you look closely, for example, the cross 3 by 3 pixels is actually 4 by 3 pixels. Look ...
0
votes
1
answer
87
views
Rectangle intersections with Java AWT
I have two rectangles, and I want to figure out which side they are intersecting on. I can use Rectangle.intersects(Rectangle) but it only tells me that the rectangles are intersecting. What I am ...