Oshan96 / CustomStage

A JavaFX UI framework to create fully customized undecorated windows
Apache License 2.0
199 stars 18 forks source link

how to use scene #8

Closed mokun closed 6 years ago

mokun commented 6 years ago

Hi @Oshan96 ,

If I don't want to use fxml when setting up a scene, how do I proceed with adding the scene to the CustomStage ?

Say I want to define a stack pane to sit inside the stage.

        Scene scene = new Scene(new StackPane(), 800, 600);
        stage.setScene(scene);

As soon as I do stage.setScene(scene), the title bar will be covered and I won't be able to drag the window/stage or use the buttons.

So how should I add a stack pane or an anchor pane to a custom stage ?

Oshan96 commented 6 years ago

Hi there, currently, CustomStage is using a previously created Scene, so there is a provided method on this library called 'changeScene(Pane)' this method allows you to pass a Pane to the scene which will be used as the 'root' of the window.

customStage.changeScene(new StackPane());

See the documentation

mokun commented 6 years ago

okay I see.

Node scene1 = manager.getScene("Scene1"); //gets Scene1.fxml view

if I do the above, scene1 is actually a node, not a scene, which is a little confusing.

Is there any way to get back the instance of scene ? I need to manipulate the scene directly.

Thanks much !

Oshan96 commented 6 years ago

Oh yeah. It is a Node. The 'Scene' in this library refers to the particular view. Anyways, since customestage is a sub class of Stage,

stage.getScene();

should do the trick for you.

Oshan96 commented 6 years ago

Also to be noted that, the sample set of code you provided there is an implementation of "SceneManager" tool within CustomStage.

And the SceneManager cannot be used to manipulate fxml files (Nodes) unless the "DefaultSceneManager" is activated

You should refer the wiki.

mokun commented 6 years ago

stage.getScene(); should do the trick for you.

I'll test to see if stage.getScene(); can still return a Scene instance and not a Node.

One problem is that when I do stage.setScene(scene), the title will be covered up. So I lose the ability to drag the window since I need to hover the mouse pointer over the title bar to do the dragging.

Oshan96 commented 6 years ago

stage.getScene(); will return the Scene of the CustomStage which includes all the basic components of it (Even the title bar).

stage.setScene(scene); will put the given Scene to the CustomStage overriding its default Scene which includes all the components (like said, even the title bar).

If you want to change the view (the main view of the window), the 'stage.changeScene(node)' method is provided to do so, and unless otherwise you want to manipulate the Scene itself, i strongly recommend you to manipulate the current scene of CustomStage via Scene scene = stage.getScene(); and change the 'scene' object accordingly.