What is the main role of the scene in javafx? - javafx

A stage in javafx requires exactly one scene, and a scene requires exactly one root node.
So I want to know what's the main role of the scene? It seems like a scene connects two sides that can be connected directly without an intermediate.
I want juste to understand the logic.
Thank you.

Stage represents a native system window. Scene is the content of this window with JavaFX controls, nodes, stylesheets, etc.
You can change Scenes inside a Stage during your UI workflow without a need to create a new system window each time.

Related

Is it possible incorporate a Stage into a primaryStage javaFX?

I need to pass to a native method the handle of a javaFX window on which to render a world made with OSG (Open Scene Graph).
I understood that on javaFX only the Stage has this native handle, all the other objects, for example Nodes and Pane do not have a native handle.
So I thought, if it were possible to insert the Stage (for native rendering) and javafx widgets into the primary Stage, I would have the possibility to manage different levels, so that I could superimpose javaFX objects on the OSG rendering.
Do you have any idea?

JavaFX Scenebuilder: How to connect pages with each other?

I am working on a JavaFX project and the problem that I am facing is that I can't connect the different pages for my application. I can't go from another FXML file to another FXML File. For example I have two FXML Files. One for the Login Screen and one for the Menu. What I want is that when I click on the login button of my Login screen that I immediately go to my Menu Screen.
One way to transition from one screen to another is to assign a new Scene to a Stage using the setScene method of Stage.
Another way is to assign a root node like BorderPane to the Scene and swap FXML using its set methods(setTop, setCenter etc.) as per your application needs (In your case, on logging in).

JavaFX nodes - How to make them resizable by the end user?

I am developing a JavaFX application where a class I have developed (extended from javafx.scene.Parent) is created on-the-fly based on what entry the user has clicked in a ListView control.
Just to be clear about this node, it is not created using a layout tool like SceneBuilder, it is created at runtime based on the user's actions.
The constructor for my custom node class creates a VBox and a Label and uses passed coordinates (X,Y) in the constructor method to set its own Layout coords. I then use a custom utility class to make the node draggable. This new node is then added to the main application Pane.
However, I have failed to find out how I can make these nodes resizable by the user. That is, allow the user to mouse over the corner of the node, hold and drag to resize. An operation that all users are used to, no matter what the OS.
Has anyone done anything like this in JavaFX? (My searches on the subject only seem to pull up subjects on the automatic resizing that a parent node does with its child nodes.)
Many thanks,
Ian.
As you can see on the documentation of VBox you can only define minimum, prefered and maximum range, there's not really a way to make it manually resizable.
The only proper solution to solve your problem is to develop your own class to do it, because what you want seems very specific, with your problem description, I don't think use some layouts or panels will do what you exactly want.
I found something that you can use : Dragging to resize a JavaFX Region
This allows you to resize a region, all you have to do after is to put you VBox in this region, but notice in this article that :
Only height resizing is currently implemented.
This code won't work in JavaFX8, you'll have to check the comment to see how it worls in JavaFX8
Hope this helps.

how to bind scene with stage in javafx2

Actually I want to switch from one scene to another scene on particular event. So i can do that by setting scene of the stage without binding but i want to bind my stage with scene as soon as a flag changes my scene will change automatically....pls help
The JavaFX Demos and Samples Downloads contains an application called FXML-LoginDemo. It demonstrates how to change scenes in a stage. The important part happens in the method replaceSceneContent. As for automatically changing the stage when a flag in your application is updated, there are several ways to do that. I recommend using a PropertyChangeListener or using JavaFX withCDI and then using CDI events. I used the latter approach in my application and it works really well.

QGraphicsScene::changed() always returns a single rect sized to the app window

In a Qt 4.7.1 Windows app, a slot that's connected to QGraphicsScene::changed() is fired as expected but the dirty region count is always 1 and the rect size I get is always the same as my app window. I tried calling QGraphicsView::setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate); but that didn't help.
Is there a way to tell Qt to only give me the area(s) of the page that changed?
An update in a QGRaphicsView is different from the one in a QGraphicsScene. Update in the view is caused by the need to repaint the view. With or without changing the scene. This typical is from window (resize) and view changes (scroll). An change in the scene will also trigger an update to the view.
A change in a scene is the change of the content of the scene. Like adding or removing a item, scaling or translating of the transformation. This will emit the changed() signal. All views displaying that scene will also update themselves for the display.
For example. Scrolling a view around will not generate any scene update since nothing in the scene changed. The paint() function of items in the scene will be called to repaint. But no changed() signal will be emitted from the scene.
If you changed the scale of the scene for instance, the whole scene changed. In addition to the whole repaint, the scene will emit changed() signal and indicates the whole scene changed. But if you add a new item to the scene, changed() should indicate only the rect of the new item.
If you want to know what part of the scene need to be repainted, in addition to calling QGraphicsView::setViewportUpdateMode(), you need to install a event filter to the view and check for QEvent::Paint. Note that the region and rect in QPaintEvent is in local coordinate of the view, which can be different from the scene. But QGraphicsView has many mapping functions to do the conversion.

Resources