Skip to content

Commit 3ce7c77

Browse files
IVS-189 Improve autoresizing
1 parent 40e62f8 commit 3ce7c77

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

testar/src/nl/ou/testar/jfx/MainController.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package nl.ou.testar.jfx;
22

33
import javafx.scene.Parent;
4+
import javafx.scene.Scene;
45
import javafx.scene.layout.AnchorPane;
56
import javafx.scene.layout.BorderPane;
67
import javafx.scene.layout.Pane;
78
import javafx.scene.layout.VBox;
89
import javafx.scene.shape.Rectangle;
10+
import javafx.stage.Stage;
11+
import javafx.stage.Window;
912
import nl.ou.testar.jfx.core.NavigationController;
1013
import nl.ou.testar.jfx.core.NavigationDelegate;
1114
import nl.ou.testar.jfx.core.ViewController;
@@ -31,6 +34,8 @@ enum Mode {
3134
private SettingsController settingsController;
3235
private MiscController miscController;
3336

37+
private Stage stage = null;
38+
3439
public DashboardController getDashboardController() {
3540
return dashboardController;
3641
}
@@ -44,6 +49,7 @@ public MainController(Settings settings, String settingsPath) {
4449
}
4550

4651
private void setupMode(Parent view, Mode mode) {
52+
4753
if (mode != this.mode) {
4854
// final Label titleLabel = (Label) view.lookup("#titleLabel");
4955
// final Button btnBack = (Button) view.lookup("#btnBack");
@@ -73,9 +79,17 @@ public void onViewControllerActivated(ViewController viewController, Parent view
7379
AnchorPane.setTopAnchor(view, 0.0);
7480
AnchorPane.setRightAnchor(view, 0.0);
7581
AnchorPane.setBottomAnchor(view, 0.0);
76-
// btnBack.setVisible(navigationController.isBackAvailable());
77-
// contentPane.getChildren().removeAll();
78-
// contentPane.getChildren().add(view);
82+
83+
if (stage != null) {
84+
double width = stage.getWidth();
85+
double height = stage.getHeight();
86+
87+
view.setVisible(false);
88+
stage.sizeToScene();
89+
stage.setWidth(Math.max(width, stage.getWidth()));
90+
stage.setHeight(Math.max(height, stage.getHeight()));
91+
view.setVisible(true);
92+
}
7993
}
8094
});
8195

@@ -95,6 +109,7 @@ public void viewDidLoad(Parent view) {
95109

96110
btnHome.setOnAction(event -> {
97111
setupMode(view, Mode.HOME);
112+
98113
});
99114

100115
btnSettings.setOnAction(event -> {
@@ -107,4 +122,9 @@ public void viewDidLoad(Parent view) {
107122

108123
setupMode(view, Mode.HOME);
109124
}
125+
126+
@Override
127+
public void viewDidAppear(Parent view) {
128+
stage = (Stage) view.getScene().getWindow();
129+
}
110130
}

testar/src/org/fruit/monkey/Main.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,6 @@ public void onViewControllerActivated(ViewController viewController, Parent view
394394
stage.setScene(new Scene(view));
395395
stage.sizeToScene();
396396
stage.show();
397-
// stage.setMinWidth(stage.getWidth());
398-
// stage.setMinHeight(stage.getHeight());
399397
}
400398
});
401399
}

0 commit comments

Comments
 (0)