Skip to content

Commit 0194402

Browse files
committed
Add window close button
1 parent f16859d commit 0194402

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
This project is :
66
* Maven + JavaFX + Openjdk 12 + Eclipse
77
* an example with custom css
8-
* an example of a JavaFX Task
8+
* with borderless window
9+
* drag and drop of the window
10+
* a window close button
11+
* an example of a JavaFX background Task
912

1013
![](https://github.com/neokeld/JavaFXDesign/blob/master/readme-assets/1.png)
1114

1215
This project is also :
1316
* a fiction with a delivery management company Deliverat
14-
* featuring Maïté
17+
* featuring [Maïté](https://fr.wikipedia.org/wiki/Ma%C3%AFt%C3%A9)
1518
* the purple color from https://v2.grommet.io/
16-
* no close button...
1719
* based on https://github.com/k33ptoo/RestaurantMgtSampleUI

readme-assets/1.png

4.95 KB
Loading

src/main/java/design/Controller.java

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package design;
22

3+
import javafx.application.Platform;
34
import javafx.event.ActionEvent;
45
import javafx.fxml.FXML;
56
import javafx.fxml.FXMLLoader;
@@ -59,6 +60,9 @@ public class Controller implements Initializable {
5960

6061
@FXML
6162
private Pane pnlSignout;
63+
64+
@FXML
65+
private Button btnCloseWindow;
6266

6367
@Override
6468
public void initialize(URL location, ResourceBundle resources) {
@@ -119,4 +123,8 @@ public void handleClicks(ActionEvent actionEvent) {
119123
pnlSignout.toFront();
120124
}
121125
}
126+
127+
public void handleCloseWindow() {
128+
Platform.exit();
129+
}
122130
}

src/main/java/design/Home.fxml

+5
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@
230230
</Pane>
231231
</children>
232232
</StackPane>
233+
<Button fx:id="btnCloseWindow" layoutX="1024.0" layoutY="4.0" mnemonicParsing="false" onAction="#handleCloseWindow" prefHeight="20.0" prefWidth="21.0" style="-fx-border-color: transparent; -fx-background-color: transparent;" stylesheets="@style.css" text="X">
234+
<HBox.margin>
235+
<Insets />
236+
</HBox.margin>
237+
</Button>
233238
</children>
234239
<effect>
235240
<DropShadow color="#1b1eeb" />

src/main/java/design/Main.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import javafx.stage.StageStyle;
1111

1212
public class Main extends Application {
13-
private double x, y;
13+
private double x;
14+
private double y;
1415

1516
@Override
1617
public void start(Stage primaryStage) throws Exception {
@@ -19,17 +20,16 @@ public void start(Stage primaryStage) throws Exception {
1920
//set stage borderless
2021
primaryStage.initStyle(StageStyle.UNDECORATED);
2122

22-
//drag it here
23+
//window drag and drop
2324
root.setOnMousePressed(event -> {
2425
x = event.getSceneX();
2526
y = event.getSceneY();
2627
});
2728
root.setOnMouseDragged(event -> {
28-
2929
primaryStage.setX(event.getScreenX() - x);
3030
primaryStage.setY(event.getScreenY() - y);
31-
3231
});
32+
3333
primaryStage.show();
3434
}
3535

0 commit comments

Comments
 (0)