1
我想在某些用戶操作後顯示NotificationPane。我的應用程序有多個場景,NotificationPane應顯示在當前活動的場景中。NotificationPane不會出現在場景
整件事情與通知一起工作,它在我需要它時彈出。 但我不知道如何使這項工作的NotificationPane。
步驟我迄今所取得:
- 我tryed直接把NotificationPane我的現場,並撥打
show()
- 它的工作原理。 - 如今的想法是通過調用
stage.getScene().getRoot()
獲得當前窗格,它換到NotificationPane,然後調用show()
- 它不工作,我不知道爲什麼。 ((BorderPane) pane).setCenter(new Label("TEST"));
此行與文本標籤更換按鈕,所以stage.getScene().getRoot()
將返回正確的對象
我做了一個簡單的程序來測試性能。一個按鈕可以調用NotificationPane。 有什麼建議嗎?
這裏是我的測試程序:
package application;
import org.controlsfx.control.NotificationPane;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Button notificationPaneButton = new Button("NotificationPane");
notificationPaneButton.setOnAction(e -> showNotificationPane(primaryStage, "Notification text"));
VBox vbox = new VBox(5);
vbox.setAlignment(Pos.CENTER);
vbox.getChildren().addAll(notificationPaneButton);
BorderPane borderPane = new BorderPane();
borderPane.setCenter(vbox);
primaryStage.setTitle("Notifications test");
primaryStage.setScene(new Scene(borderPane, 300, 200));
primaryStage.show();
}
public void showNotificationPane(Stage stage, String message) {
Parent pane = stage.getScene().getRoot();
// ((BorderPane) pane).setCenter(new Label("TEST"));
NotificationPane notificationPane = new NotificationPane(pane);
notificationPane.setText(message);
if (notificationPane.showingProperty().get()) {
notificationPane.hide();
System.err.println("hide");
} else {
notificationPane.show();
System.err.println("show");
}
}
}