Convert Shape from awt to Shape in javafx - java

I want to display Shape on Pane in JavaFx. I am using oracle JGeometry object selected from spatial database, it has a method createShape() but it returns java.awt.Shape.
Is it possible to create JavaFx object also so easily? Maybe I am just blind but I haven't found anything and don't want to program too much stuff on top. Thank you

Java only supports a handful of shapes, so it is not very difficult to write a little converter but if all you want to do is to draw the AWT shapes on a JavaFX canvas, then maybe this library can be helpful: http://www.jfree.org/fxgraphics2d/

Related

Android Customized Barchart

I need to create a chart like this picture bellow in Android.
and I am already aware of MPAndroidChart and AndroidHelloCharts libraries. but none of them are capable of drawing such thing.
do you know any way to create a chart like this?
please explain and at least suggest me some tutorials or articles that are related to what I am about to do.
thank you
Its actually pretty simple to create your own bar chart.
First you need to use drawRect to draw a rectangle.
And then drawText to draw text below the rectangle.
You may have noticed that both methods take a paint object as the parameter , you can think of the paint object like a brush. So you set the color to the brush and draw different elements.
I have written about it
here

Manipulating Pixels(Drawing) in Java

This is not a typical "what library do i use?" or "is there an API for that". Using lines of code I create not implementing them through a library of sorts. Is there any documentation on how to actually create a window, and within that window draw a line from pixels?
I just want to understand how its done, and not learn through a library which does it for me.
Previously tried:
JavaFx
Swing
If you want to draw a line in a window, you'll ultimately have to create a BufferedImage, set pixels in that BufferedImage according to some drawing algorithm (like Bresenham's), then put the BufferedImage in the window.

Java 2d graphic library

Hi I am trying to create simple 2d graphic editor. I need some library which will create shape from given points(draw lines between these points) and then user can move this shape with mouse or scale this shape with mouse. I need points, because I have Oracle Jgeometry shape saved in database and I need to visualize it. Could you please help me?
I found jGraph but I don't know, how to create shape from points, or get these points from shape
Instead of reinventing the wheel I would suggest using svg. There is a pretty nice implementation from Apache: https://xmlgraphics.apache.org/batik/
You could generate svg from your data (which is pretty easy) and pass it on to batik to show in a component or you can use their bindings to Java2D to draw.
As a bonus you can use existing tools like Inkscape to edit you drawings further.
There are existing projects which use this to do simmilar things like you want: https://xmlgraphics.apache.org/batik/uses.html

Is it possible to store constructed images for display later using Java Swing?

I am a C/C++ programmer trying my hand at Java for the first time. I'm currently working on a program that reads in a bunch of data and builds a map. I want to give the user the option to toggle various features of the map using check boxes.
In the Win32 API, I was able to accomplish this by pre-building the features on transparent bitmaps and then BitBlt()ing them over top one another. Does Java Swing support something similar? I imagine I'm not the only person who has ever wanted to do this. Building the features is relatively slow, so I only want to generate the layers once and then block copy them to the JPanel I'm using as a display.
Thanks in advance!
You could dynamically create BufferedImage objects, with alpha channels, then only paint this on a frame if the checkbox is checked.
You can store images in Swing using the BufferedImage class, and then use that to later draw the final image.
http://docs.oracle.com/javase/6/docs/api/java/awt/image/BufferedImage.html
The final image can later be painted on to the JPanel (probably by overriding the JPanel's paintComponent method) by using the alpha values of the images.

Draggable rectangles in Java 2D [duplicate]

This question already has an answer here:
Closed 10 years ago.
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"?
JHotDraw was designed as "a Java GUI framework for technical and structured Graphics." The linked JHotDraw Pattern Language: JHotDraw Domain Overview illustrates how to customize drawing editors. The sample org.jhotdraw.samples.draw.Main is a reasonable starting point, and JModeller is a simple UML editor built using the framework.
Are you forced to swing?
If not you might have look at draw2d which is a java library that works on a SWT canvas. You can find some examples of draw2d here.
You can only add MouseListener to a (J)Component. All Java2D stuff is painted on the component. If you manage all shapes in a List you can search for the correct shape under the mouse courser, move it and repaint the component.

Categories

Resources