我想用JavaFX UI(all-in-one)开发服务.当用户单击"关闭"按钮时,我想将应用程序移动到系统托盘并在所有侦听器处于活动状态时保持打开状态.
目前,我所取得的成就是当有人点击关闭按钮时,应用程序会被最小化.
任何人都知道如何将应用程序移动到托盘(至少在Windows系统中)?
谢谢
我创建了一个引发内存泄漏的示例应用程序.
问题是我需要"重新加载"场景.如果我有两个场景(Bar和Foo),每个场景一个按钮(ButtonBar和ButtonFoo),按钮会改变当前场景,创建一个新场景.如果我继续单击ButtonBar和ButtonFoo 5分钟(或更短),那么该简单程序的内存消耗会越来越高.
Bar.java
public class Bar implements Initializable {
@FXML
private Label label;
@FXML
private void toFoo(ActionEvent event) {
try {
Button button = (Button) event.getSource();
Parent root = FXMLLoader.load(getClass().getResource("Foo.fxml"));
Stage currentStage = (Stage) button.getScene().getWindow();
currentStage.setScene(new Scene(root));
} catch (IOException ex) {
Logger.getLogger(Bar.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
Run Code Online (Sandbox Code Playgroud)
Foo.java与更改de fxml加载相同.
fxml只包含一个按钮:
<Button id="buttonBar" layoutX="126" layoutY="90" text="Bar!" onAction="#toFoo" fx:id="buttonBar" />
Run Code Online (Sandbox Code Playgroud)
是否存在真正的内存泄漏问题?有谁知道另一种方法吗?我希望这个应用程序能够保持活力并永远地进行更改,就像服务一样.谢谢
我想从我加载FXMLoader的场景中获取控制器.用例是:
我启动的任务显示了一个新的场景使用
Parent p = FXMLLoader.load(getClass().getResource("foo.fxml"));
Scene scene = new Scene(p);
stage.setScene(scene);
Run Code Online (Sandbox Code Playgroud)
在那之后,我有空场景.
现在我这样做来填充组件
AnchorPane pane = (AnchorPane)((AnchorPane) scene.getRoot()).getChildren().get(0);
for(Node node : pane.getChildren()){
String id = node.getId();
if(id.equals(NAME)){
((TextField)node).setText(value);
}
}
Run Code Online (Sandbox Code Playgroud)我的问题是,有更简单的方法吗?我有一个FXML中指定的控制器
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="526.0" minWidth="356.0" prefHeight="526.0" prefWidth="356.0"
xmlns:fx="http://javafx.com/fxml" fx:controller="bar.foo">
Run Code Online (Sandbox Code Playgroud)
我想获取带有绑定值的实例(在这种情况下,TextField名为name)
提前致谢