How to bind Circle CenterX and Slider Value - javafx

Got problem when I tried to bind a slider with a circle centerX, and don't know how to solve it... So the ball has to go from left to right, with an animation(i guess that an animation is the best solution for that) and the slider has to return the ball somewhere in the scene, but the slider doesn't follow the movement of the ball while the animation is playing... Any help is appreciated.

In order to bind two values together you need to use bindBidirectional method instead of bind. Also when you put a node in a container like the BorderPane it layouts the children based on some rules. If you want to manage the position of the circle yourself you will have to specify the intention with cr.setManaged(false).

Related

Drawing node on top of the others in HBox

I am looking for a way to draw a node on top of the neighbouring ones in a HBox. Default behaviour means it is drawn on top of the previous one, but that also means the next one is drawn on top of it. For other containers, one could use the Node.toFront(), but changing the position of the node in the list containing a HBox's children also changes the actual position in the HBox, which is unwanted behaviour in my case. I appreciate any help, thank you.
EDIT:
The overlapping occurs when applying a DropShadow effect on an Ellipse and wrapping them in a StackPane along with a Text. It looks like the effect has a weird interaction with the HBox, as it works as intended without it. After adding the effect, it allocates more horizontal space for the ellipse, but not enough to cover the margins of the effect. Also, when clicking anywhere in the whole right half of the black rectangle, the mouse click is dispatched to the stackPane event handler, not to the rectangle's.
This happens
In VBox and HBox, the Node.toFront() and Node.toBack() functions will change the layout, so they are not usable. If you are using JavaFX 9+,you can use the viewOrder commands to change the rendering order of the Node in its Parent:
Node.getViewOrder()
Node.setViewOrder()
The default value of viewOrder is 0, so setting it to -1 will render it above all others. You can customize this to get specific orders. It also has a CSS property -fx-view-order.

Adding Shapes to GridPane results in wrong Position

I got the task to draw some points on a map. Wrote some code but currently every point I create via shapes will be added to the wrong position inside of my gridpane. Oh and I'm using JavaFX.
I added an imageView to the index 0,0 of my GridPane and every point is created through x and y position of the MouseEvent on the imageView.
After that I added the created point as a child of the GridPane and it's displayed at the center of the y-axis of the first grid.
Tried different things like anchorPanes and canvas but can't seem to get it working.
Code of my View:
http://pastebin.com/dCb7EN4d
Code of my Main:
http://pastebin.com/vp5tzxkG
I hope that's enough ^^'
pls help!
Greetings,
Ben
GridPane is a managed layout: it will position nodes that are added to it via the properties you set (using defaults if you don't set them). So when you add your circles to the grid pane, since you don't set any properties, it will place it in cell (0,0) and align it within that cell using default settings; i.e. it ignores the centerX and centerY properties.
What you should really do here is use a layout that does not manage the positioning of the nodes for you, such as a Pane (or possibly a Group). You can put the ImageView and the Circles in the pane, and then place the pane in the rest of your layout (in the scroll pane, I think).
The other option you have is to call setManaged(false) on the nodes you add to the GridPane in order to instruct the GridPane not to position them, though this feels like more of a workaround.

Change position of a circle?

I want a circle object to change position, I would imagine that I do the same as I do with markers -
marker.setPosition(latlng);
So -
circle.setPosition(latlng);
But this doesn't work. The marker changes position, but the circle doesn't. All I can find is this link - https://developers.google.com/maps/articles/mvcfun
Would that seem like the best way to go about this? I've not had a proper ready through it, so I'm going to try implement the above.
You need to change the center property of the circle to move it (it doesn't have a position property)
circle.setCenter(latlng)
https://developers.google.com/maps/documentation/javascript/reference#Circle
Just an extension for above answer
MyLocationCircle.setCenter(new google.maps.LatLng(latitude, longitude));

Drawing a rectangle on a flex canvas is there a better way than

To draw a "selection rectangle" from the mouse down , mouse move then remove it on mouse up i currently do the following:
My board is a canvas,
On mouse down i create a new UIcontainer i set his borders.
I update his width and height related the the mouse move position,
on mouse up i remove this child UIcontainer.
Do i have to create a new component for this kind of task or there is a better (lighter way) in flex ?
Thanks,
Here is an Flex selection rectangle example, although I think it won't be a better/lighter way, perhaps you can get some nice ideas from it.
I'd say you got it right.

When handling a flash.events.MouseEvent, how do I find the localX/Y with respect to the currentTarget?

I have a component which draws a grid of things and I want a small highlight square to follow the mouse around highlighting the square that the mouse is currently over.
The whole grid is basically just one big sprite (it's a very large grid and this was faster than using pre-existing components) and the highlight square is another sprite which I'm trying to move around according to the mouse position.
So, what I have is a MouseEvent.MOUSE_MOVE handler attached to the grid sprite and this tries to determine where the mouse is and what square it's over so that it can move the highlight square to the right place. I was using localX/localY for this, but as soon as I move the highlight sprite under the mouse, these become local to the highlight and not the grid!
I was toying with stageX/Y as well, but these seemed to become pretty useless when the stage is scrolled or your component is hiding in nested display containers.
Basically, i think, you want to check the the grid components mouseX and mouseY property which will give you the mouse coordinates relative to that component. Then a little bit of maths should be able to give you what grid element you are over.
Assuming your highlight sprite is a sibling to the grid and they are both children of the main application, and you've drawn child sprites (squares) within the grid: You could add event listeners to each of the grid's square sprites. On rollover, highlight the square. Then you probably won't need to perform any translation of grid or mouse coordinates using grid.localToGlobal(new Point(targetSquare.x, targetSquare.y)) or highlightSquare.globalToLocal(grid_point).

Resources