I want to build an JavaFX Graphics Editor with object-orientated patterns, such as Prototype, Composite, Singleton, etc. The problem I have, is to resize an already drawn shape in my AnchorPane. So my idea would be to click i.e. on a rectangle, then a sourrounding border appears which small buttons in each corner to start resizing for that rectangle. Imagine Photoshop resizing, there you also hava such a border, you know. So how can I do this?
Thanks in advance ;)
Here is my solution shown in my Graphics Editor.
https://github.com/djessich/GraphicsEditor
Related
So, I have a grid of rectangles in my scene and I want to give it a border to visually seperate it to the others. I am currently using grid.setGridLinesVisible(true); and that works fine, but I am sure this isn't supposed to be used for that.
I tried setting a border with nodes[j][i].setStroke(Color.BLACK); and this works too, but now my whole grid is getting a lot bigger because it's drawing the border on the outside of the rectangle and therefore resizing it.
Is there a way to draw a border/stroke inside of a rectangle to keep the transformation?
I already looked up the documentation but there isn't such a function.
Thanks for the help!
You can use setStrokeType for your rectangles to draw the border inside using StrokeType.Inside:
nodes[j][i].setStrokeType(StrokeType.Inside);
I want to create a tile editor sort of program where I have a viewport for rendering on the left side of the program, and then a panel of buttons on the right to use for opening files, saving the tiles etc... I was going to use LWJGL to do this, but it seems theres no good way to do it.
Essentially I guess I'm asking, how do I have a viewport for rendering using g.DrawImage or something, and then also have a panel of buttons next to that viewport?
You can do this using jME3 as they support rendering in a canvas on a Swing window. There is even a tutorial on doing it in the tutorials section of the website.
You can also do it using a fully rendered window and then putting the buttons inside the scene. I'm surprised LWJGL doesn't support this though as jME3 is built on top of LWJGL.
I am working on a small project which requires me to load images into a window and then move them around at will.
Thus far I can load images onto a JPanel simply by using a graphics object to draw them to the JPanel.
Now I'm faced with the challenge of figuring out how to differentiate between the various images I've loaded when I click on them so I can drag them around the screen.
Any ideas?
If you use a JLabel for each image, and make the JLabels subcomponents of the JPanel, it'll automatically draw the image, and you can add MouseListeners to each of them to be able to drag them around the screen.
Use the Component Mover to drag any component around the screen.
I'm building a domino game in java and I am using modified rectangle2d's to draw my tiles. To drag a tile I use mouse events to change the tiles coordinates and redraw the JPanel.
This all works great and very smooth, until I start using the frames glassPane, I use the glassPane to be able to drag a tile from one JPanel to another.
It works, but rendering is quite slow when I paint on the glassPane. I've tried to use clipping when repainting, but it makes no difference.
Does anyone have an idea?
thnx.
It seems when a glassPane is visible on your RootPaneContainer, all repaint events behind the GlassPane have their clip set to fill the entire RootPaneContainer. This may be overriding your manually specified clip rect.
Is there any way I can print/show images on top of each other. The picture on top will always be positioned a little lower so that the one under will show partially. How can I decide which image is on top of what image? What layout lets me do this kind of positioning?
Is there any way that I can make a border appear on the image when I click it, and then move to (doesnt have to be animated, can be a "jump") where I click next inside the JFrame.
I've been trying to do this whole day now (I'm pretty new to swing), before I carry on I'd like to know if I'm trying something impossible.
So far I've been printing the images right on to the JFrame as JPanels... Inside the JPanel I add in the paintComponent(Graphics g) method: g.drawImage
Sounds like a Swing tutorial is in order.
What you're describing shouldn't be very hard. Instead of painting the images directly, load them up in ImageIcons, and pass those to JLabels. That way you can manipulate your images as JComponents, using layout managers, or direct coordinates by setting the layout to null. You can set the Z-Order with setComponentZOrder regardless of the layout you choose. You can draw borders by adding swing borders (see BorderFactory) to the JLabels. You can handle the manipulation with MouseListeners.
Look into Root Panes. You may be able to do something with the Layered Pane or the Glass Pane. I would try the Layered Pane first.