【发布时间】:2016-08-31 06:48:26
【问题描述】:
我想将自定义节点显示为 ControlFx NotificationPane 的内容。我尝试将自定义节点作为参数放入 NotificationPane 类,就像NotificationPane np = new NotificationPane(customNode) 一样,但没有显示。
我做了一个简单的可运行类来演示我刚才解释的内容。
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.controlsfx.control.NotificationPane;
public class NotificationPaneExample extends Application{
public static void main(String[] args) { Application.launch(args); }
@Override
public void start(Stage primaryStage) throws Exception {
VBox root = new VBox();
TableView tv = new TableView();
Label customNode = new Label("This is a custom made node");
NotificationPane np = new NotificationPane(customNode);
np.setContent(tv);
Button button = new Button("Add");
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
np.show();
}
});
root.getChildren().addAll(button, np);
primaryStage.setTitle("Notification Pane Example");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
}
【问题讨论】:
-
因为在
NotificationPane中,设置内容实际上是设置不是在NotificationPane 内的节点,而是显示通知的那个节点。在 NotificationPane::setContent() 的 javadoc 中,它显示/** * Set the content to be shown in the scene, * <strong>that is not within</strong> the notification bar. * @param value */。这个 SO 答案可能会解决您的问题:stackoverflow.com/a/46404703/1852598
标签: javafx-8 controlsfx