Resize Pane on MouseDragEvent

Viewed 270

I am creating a Desktop Simulator Game inside of Java.

I have a working desktop where I can spawn and destroy various in-game apps.

I am trying to find a way to resize each app.

Here is slight edit (minus CSS styling and a custom BorderPane class that allows Pane dragging) of my QuickPad (Notepad) in-game app.

// 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 change the size of the app after it's 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 click on resize_text (or a similar object) it would change the node.setPrefSize() (as if you were to grab the corner of a desktop window to resize it) until I released it.

I have looked at other options such as DragResizeMod: https://github.com/varren/JavaFX-Resizable-Draggable-Node/blob/master/src/sample/DragResizeMod.java. This solution, while working, consumes all mouse events besides the current app (you cannot interact with anything else in-game).

0 Answers
Related