2016-08-31 5 views
0

Ich möchte einen benutzerdefinierten Knoten als Inhalt von ControlFx NotificationPane anzeigen. Ich habe versucht und den benutzerdefinierten Knoten als Parameter NotificationPane-Klasse, wie so NotificationPane np = new NotificationPane(customNode), aber nicht angezeigt. Ich machte eine einfache runnable Klasse, um zu demonstrieren, was ich gerade erklärt habe.NotificationPane zeigt keinen benutzerdefinierten Knoten an

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(); 
} 

} 

Antwort

0

Warum versuchen Sie nicht, einen Dialog zu verwenden? Ich hatte das gleiche Problem vor einiger Zeit, und ich löste es die Klasse 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); 
          }); 
         } 
        } 
mit

hier ist ein Beispiel dafür, was ich tat, ich hoffe, ein Dialog wäre hilfreich Verwendung für Sie

+0

Weil ich die benutzerdefinierte möchte Knoten, der vom übergeordneten Knoten heruntergleitet, in diesem Fall TableView –