I am creating a game for a desktop simulator inside Java.
I have a desktop where I can create and destroy various game applications.
I am trying to find a way to resize each application.
Here is a little editing (minus the CSS style and the custom BorderPane class that allows you to drag the panel) of my QuickPad (Notepad) application in the game.
// The Node Window (In-Game App) BorderPane node = new BorderPane(); node.setPrefSize(300, 225); // Window Size // position the node node.setLayoutX(10 + node.getPrefWidth()); //TitleBar HBox title_bar = new HBox(); title_bar.setPrefHeight(10); title_bar.setPadding(new Insets(0,0,0,5)); //Name Label win_name = new Label("Quickpad"); //Spacer Region spacer = new Region(); HBox.setHgrow(spacer, Priority.ALWAYS); //Quit Button win_close = new Button("X"); win_close.setOnAction(close -> { root.getChildren().remove(node); }); title_bar.getChildren().addAll(win_name, spacer, win_close); title_bar.setAlignment(Pos.CENTER_RIGHT); node.setTop(title_bar); //App TextArea textArea = new TextArea(); textArea.setWrapText(true); node.setCenter(textArea); textArea.setText("Enter some text..."); //Resize HBox bottom_bar = new HBox(); bottom_bar.setPrefHeight(10); bottom_bar.setAlignment(Pos.CENTER_RIGHT); Label resize_text = new Label("||||"); bottom_bar.getChildren().add(resize_text); node.setBottom(bottom_bar); // DragEvent linked to 'resize_text' // add the node to the root pane root.getChildren().add(node);
I can resize the application after it is created by changing node.setPrefSize() .
I did some research and found this: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/input/MouseDragEvent.html
My goal would be when I resize_text on resize_text (or a similar object), it will change node.setPrefSize() (as if you have to grab the corner of the desktop window to resize it) until I release it.
I considered other options such as DragResizeMod : https://github.com/varren/JavaFX-Resizable-Draggable-Node/blob/master/src/sample/DragResizeMod.java . This solution during operation consumes all mouse events besides the current application (you cannot interact with anything else in the game).
source share