Creating TimeLine for scene changing - javafx

I Changed the scene of a stage by
((Stage) Node.getScene().getWindow()).setScene(scene);
but I am not able to add any timeline during scene changing.
can anyone suggest me an idea to do it ?? plz

I assume you want to anime a transition between screens in your GUI? For that I recommend you don't switch the Scene but instead switch out Panes (screens being Panes). The following steps should work:
Pick an appropriate root node. The screen (let's call it screen1) you want to show should be a child of that root node.
If you want to replace screen1 with screen2, using a fade transition for example, you could add screen2 to the root node and place below screen1.
Then create a FadeTransition to fade out screen1.
Screen2 should now be showing instead of screen1. Don't forget to remove screen1 from the root node to keep your scenegraph small.
You can adapt this technique to whatever transition you like.

Related

Aframe - load a scene through click on a thumb

I am looking for a way to load an AFrame Scene through the click on a thumb.
I am trying to use a picture slider, and every picture should have a 3d scene behind it. So if i click a picture in the slider, the aframe scene should pop up in the foreground, with a different sky texture for example.
I tried multiple ways, but nothing really works. I can load a new scene through a new window, but that's not a good way.
I would appreciate any help that could lead me on the right path. :) :D
Cheers, Max
Have an A-Frame scene in the background (or somewhere on the page) <a-scene embedded style="z-index: -1"></a-scene>. On the click of the picture, set the scene's z-index to the foreground and change whatever else you need in the scene to match the picture.
var aframeScene = AFRAME.scenes[0];
yourPic.addEventListener('click', function () {
aframeScene.style.zIndex = 9999;
aframeScene.querySelector('a-sky').setAttribute('src', 'newImage.jpg');
});

expand qgraphicsrectitem to cover complete scene and expand all children's in same proportion

I have created a QGraphicsView with a scene set on it with QGraphicsRectItem in it.
[fig-1]
I want that when I double click on the green rectangle marked with thick black border, the scene gets filled with only this rectangle and all its children also get expanded in same proportion.
So, when I double click , I should see something like this in complete view:
I have handled the double click event but do not know how to handle this.
Also, when I double click again, I get back to the previous state (as shown in fig-1)
As the documentation states for QGraphicsView::fitInView
Ensures that item fits tightly inside the view, scaling the view according to aspectRatioMode.
So, assuming pView is your QGraphicsViewand thisis the rectangle you want to view, call fitInView from the overloaded double click event of QGraphicsRectItem: -
pView->fitInView(this);
Based on the comments that only the rect and its children should be visible, one option to guarantee this would be, on double-click, to create a separate scene, move the rect to the new scene and switch the view to the new scene.

How to make window fullscreen/maximized in Scene Builder?

I am making a view in SceneBuilder for my JavaFX application. I want my view to be maximized. How can I achieve this in SceneBuilder or the .fxml file?
You cannot do that using Scene Builder, since maximize or fullScreen are properties of the Stage and not the layouts set on the scene.
You can load and set the .fxml on the scene and later set the scene on the stage.
The following methods can be used on the stage :
setMaximized(boolean) - To maximize the stage and fill the screen.
setFullScreen(boolean) - To set stage as full-screen, undecorated window.
As you cannot maximize your view in fxml, you have to set the size of the stage to be maximized. There is no direct method for setting the size of the stage to be maximized in javafx 2 but there is another way you can do this. It is by manually setting the size of the stage. You can use this code:
Screen screen = Screen.getPrimary();
Rectangle2D bounds = screen.getVisualBounds();
primaryStage.setX(bounds.getMinX());
primaryStage.setY(bounds.getMinY());
primaryStage.setWidth(bounds.getWidth());
primaryStage.setHeight(bounds.getHeight());
This is the code that works for me
primaryStage.setMaximized(true);
it miximizes my window screen on the launch of the app.
I agree with Yemmy1000. primaryStage.setMaximized(true) works fine for me.
primaryStage.setScene(new Scene(root, 1800, 850));
primaryStage.setMaximized(true);
This code will go to width: 1800 and height:900 when restored down from maximum.
Two properties I found in stage which are useful.
First is setFullScreen(boolean) which will set your view to full screeb, but it will also hide all the taskbar and header of view.
Second is setMaximized(boolean) which will set you view to perfect like any other application view size.
I an using setMaximized(true) for my application.

Position JavaFX Button in a specific location

My Question is how can i position a javafx button in a specific location.
All the time that i tried to do this simple code is resulting that the Button is only located in the Center of the screen and not on my desired location.
(I'm using StackPane)
Code:
Button button = new Button();
button.setLayoutX(x);
button.setLayoutY(y);
Thanks in advance ,
Amit.
If you want to specify the exact co-ordinates of your node, you can use a Pane instead of StackPane.
Your button, if added to a StackPane or similar layout which supports alignment, must use the translate properties to move the button. You cannot use setLayoutX() or setLayoutY() with these layouts.
Try using the following command to move the button from its initial location :
button.setTranslateX(10);
button.setTranslateY(20);

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.

Resources