graphics2d

how to capture graphics primitives from Graphics2D into SVG

徘徊边缘 提交于 2019-12-23 00:24:09
问题 I need to capture the graphics primitives from calls to java.awt.Graphics2D. The calls are made through an Open Source toolkit (Apache's PDFBox) and normally rendered in a JPanel. I would like to intercept these calls and translate them to SVG so I can build a non-graphics data model (e.g. tables, graphs, etc.). I'll be happy for any type of hack at this stage, which might include: replacing the Graphics2D library with MyGraphics2D Finding a Graphics2D that supported SVG output and capturing

Drawing a JComponent inside a JPanel

梦想的初衷 提交于 2019-12-22 20:46:50
问题 I am trying to display a JComponent inside a JPanel. I am using null layout because location of the components can be changed during runtime and I have to control them. But the following code does not work. The JComponent only becomes visible on display if I explicity call the "paintComponent" method, which I think is not good practice. My JComponent Class public class MyIcon extends JComponent { private double xPos; private double yPos; private double radius = 30; public MyIcon(double xPos,

Drawing a JComponent inside a JPanel

不羁的心 提交于 2019-12-22 20:46:12
问题 I am trying to display a JComponent inside a JPanel. I am using null layout because location of the components can be changed during runtime and I have to control them. But the following code does not work. The JComponent only becomes visible on display if I explicity call the "paintComponent" method, which I think is not good practice. My JComponent Class public class MyIcon extends JComponent { private double xPos; private double yPos; private double radius = 30; public MyIcon(double xPos,

Drawing a movable line on a JPanel

会有一股神秘感。 提交于 2019-12-22 00:19:03
问题 I'm writing a program which should allow the user to create a floor plan of a room - this means they can draw lines to represent walls etc. I am using a JPanel with Graphics 2D to do all the drawing stuff and currently I have a grid set as the background for the JPanel and I can draw lines based on the mouse movement(I have an enum for the mousestate with two states - DRAGGING and IDLE). However I want to add control points to the lines so that they can be moved around the JPanel once they

SVG to Java Graphics2D

痴心易碎 提交于 2019-12-21 20:36:31
问题 Can anyone suggest some good way to generate Graphics2D object form SVG data? I've seen Apache Batic lib, but it seams that they use some JSVGCanvas that gets the URI etc… And I want a Graphics2D stuff instead of JComponent. Thanks for any suggestions! 回答1: Try to look at SVG Salamander library. On this page there are some starting tips. It's a good thing if You want only to draw some svgs. 回答2: You can also use the Flamingo SVG Transcoder, it generates pure Java2D code from a SVG file with

Java rotated text has reversed characters sequence

坚强是说给别人听的谎言 提交于 2019-12-21 12:28:07
问题 In a subclass of a JPanel I am doing this: public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; g2d.rotate(Math.toRadians(90.)); g2d.drawString(aString, 40, -40); } The letters are rotated correctly, but the second one is not in the expected position below the first (to its right, in the rotated space), but is above it (to its left), the third is above (to the left of) the second, etc. Changing the rotation angle to 45 degrees results in each

How to draw a line using y = mx +b in java?

拜拜、爱过 提交于 2019-12-20 07:28:20
问题 So I have a program that solves a system of linear equations, but that is not relevant. So what happens is that my program pass two linear equations in the form of: y = mx +b. I do not know how I would graph this using Graphics2D, I am having some trouble figuring it out. Right now I have no idea so I have no code that I could show you, but I can tell you that: That my program correctly converts Ax + By = C into y = mx + B That it would be helpful to show an example in some code possibly

How to draw a line using y = mx +b in java?

雨燕双飞 提交于 2019-12-20 07:28:20
问题 So I have a program that solves a system of linear equations, but that is not relevant. So what happens is that my program pass two linear equations in the form of: y = mx +b. I do not know how I would graph this using Graphics2D, I am having some trouble figuring it out. Right now I have no idea so I have no code that I could show you, but I can tell you that: That my program correctly converts Ax + By = C into y = mx + B That it would be helpful to show an example in some code possibly

Graphics2D circular table

丶灬走出姿态 提交于 2019-12-20 07:22:10
问题 I'm trying to build a User Interface for the RGBike POV: http://www.instructables.com/id/RGBike-POV-Open-project/ The program will display a bike wheel in form of a grid. The user can click onto the single squares and changes the colour of these. I want to build this applet in java. I'm stuck at drawing the wheel in the right way. I need to have a sort of array of every rectangle, to export the colour later. The best thing would be to draw a sort of circular table. Drawing each shape With

Java: Create global graphics object

☆樱花仙子☆ 提交于 2019-12-20 07:07:02
问题 I've extended the JPanel class to draw a graph. The problem that I've got is that I need a global graphics object in order to call it in multiple methods... As an example, here's what I'm trying to do: public class Graph extends JPanel { private Graphics2D g2d; public void paintComponent(Graphics g){ g2d = (Graphics2D)g; } public void drawGridLines(int hor, int vert){ g2d.someLogicToDrawMyGridLines(someparams); } } This returns a null pointer exception - so my question is: how do I create a