【问题标题】:NotificationPane not displaying custom nodeNotificationPane 不显示自定义节点
【发布时间】: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, * &lt;strong&gt;that is not within&lt;/strong&gt; the notification bar. * @param value */。这个 SO 答案可能会解决您的问题:stackoverflow.com/a/46404703/1852598

标签: javafx-8 controlsfx


【解决方案1】:

为什么不尝试使用对话框?前段时间我遇到了同样的问题,我使用 Dialog 类解决了它

Dialog dialogQtPrescription = new Dialog();



dialogQtPrescription.setTitle(bundle.getString("quantityPrescription.title"));
dialogQtPrescription.setHeaderText(bundle.getString("quantityPrescription.message"));
dialogQtPrescription.initModality(Modality.APPLICATION_MODAL);
dialogQtPrescription.initOwner(mainStage);
dialogQtPrescription.initStyle(StageStyle.UTILITY);

GridPane gridDialogPrescription = new GridPane();
gridDialogPrescription.setHgap(10);
gridDialogPrescription.setVgap(10);
gridDialogPrescription.add(new Label(bundle.getString("quantityPrescription.title")), 0, 0);
TextField txtQtPrescr = new TextField();
ButtonType buttonTypeNo = new ButtonType(bundle.getString("keepDefaultConfiguration.buttonNo"));
ButtonType buttonTypeYes = new ButtonType(bundle.getString("keepDefaultConfiguration.buttonYes"));
ButtonType buttonTypeCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);

dialogQtPrescription.getDialogPane().getButtonTypes().addAll(buttonTypeNo,buttonTypeYes, buttonTypeCancel);
dialogQtPrescription.getDialogPane().lookupButton(buttonTypeYes).setDisable(true);
txtQtPrescr.setPrefWidth(100);

gridDialogPrescription.add(txtQtPrescr, 1, 0);
dialogQtPrescription.getDialogPane().setContent(gridDialogPrescription);

txtQtPrescr.setOnKeyTyped((KeyEvent ke) -> {
                        if(ke.getCharacter().matches("[0-9]")){
                            dialogQtPrescription.getDialogPane().lookupButton(buttonTypeYes).setDisable(false);
                        }else{
                            dialogQtPrescription.getDialogPane().lookupButton(buttonTypeYes).setDisable(true);
                            ke.consume();
                        }
});

Optional<ButtonType> result = dialogQtPrescription.showAndWait();
if (result.get() == buttonTypeYes){
    String int_ext;
    if(toggleInternal.isSelected()){
        int_ext="I";
    }else{
         int_ext="E";
    }
                        //masterData.remove(super.getIndex());
                        //add(new DataPick(um.getRECEIVER(),um.getID_ORDER(), um.getORDER_TYPE(),um.getUPDATE_TIME(),um.getTARGET_TIME(),ans.getID_POST(),ans.getPOST_TYPE(),ans.getREF(),Integer.parseInt(ans.getQUANTITY()),0,bundle.getString("dataPick.insert"),0));
                        //Add quantity --> filtro Numero
                        //DataPick(String receiver, String id_order, String order_type, String update_time, String target_time, String id_post, String post_type,String ref, int quantity, int quantity_delivered, String report, int quantity_available) {
                        if(Integer.parseInt(txtQtPrescr.getText())>0){
                                                                        masterPrescription.add(new DataPick(txtPatientCode.getText(), txtPrescriptionCode.getText(), int_ext , txtUpdateTime.getText(), txtTargetTime.getText(),String.valueOf(masterPrescription.size()),"0",rmc.getRmc(),Integer.parseInt(txtQtPrescr.getText()),0,"feed back from Webservices",0, "", rmc.getProductNameRmc()+" "+rmc.getCodeEan()+" "+rmc.getCodeA()));

                        }else{

                            Platform.runLater(() -> {
                                Notification notification = new Notification("ERROR", bundle.getString("errorQuantity.question"), Notification.ERROR_ICON);
                                SmartDrawerTool.notifier.notify(notification);
                            });
                        }
                    }

这是我所做的一个示例,我希望使用对话框对您有所帮助

【讨论】:

  • 因为我希望自定义节点从父节点向下滑动,例如本例中的 TableView
猜你喜欢
  • 1970-01-01
  • 2015-10-10
  • 2012-07-05
  • 2021-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多