Skip to content

Commit aabd867

Browse files
authored
[BAEL-5774] Constructor vs. initialize() in JavaFX (#18838)
* [BAEL-6602] Copying text to clipboard in Java * [BAEL-5774] Constructor vs. initialize() in JavaFX * [BAEL-5774] fix: classes and contructor names
1 parent 7c2e892 commit aabd867

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

core-java-modules/core-java-swing/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66
<artifactId>core-java-swing</artifactId>
77
<packaging>jar</packaging>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.controller;
2+
3+
import javafx.fxml.FXML;
4+
import javafx.scene.control.Label;
5+
6+
public class ControllerAnnotation {
7+
private final String appName;
8+
9+
@FXML
10+
private Label appNameLabel;
11+
12+
public ControllerAnnotation(String name) {
13+
this.appName = name;
14+
}
15+
16+
@FXML
17+
public void initialize() {
18+
this.appNameLabel.setText(this.appName);
19+
}
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung.controller;
2+
3+
import java.net.URL;
4+
import java.util.ResourceBundle;
5+
6+
import javafx.fxml.FXML;
7+
import javafx.fxml.Initializable;
8+
import javafx.scene.control.Label;
9+
10+
public class ControllerInitializable implements Initializable {
11+
private final String appName;
12+
13+
@FXML
14+
private Label appNameLabel;
15+
16+
public ControllerInitializable(String name) {
17+
this.appName = name;
18+
}
19+
20+
@Override
21+
public void initialize(URL location, ResourceBundle res) {
22+
this.appNameLabel.setText(this.appName);
23+
}
24+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import javafx.scene.control.Label?>
4+
<?import javafx.scene.layout.StackPane?>
5+
6+
<StackPane xmlns:fx="http://javafx.com/fxml" fx:controller="your.package.YourController">
7+
<Label fx:id="appNameLabel" text="Example App" />
8+
</StackPane>

0 commit comments

Comments
 (0)