javafx style and cssFile

public class EffectTest extends Application {

 public static void main(String[] args) {
    launch(args);
  }

  @Override
  public void start(Stage stage) {
    stage.setTitle("ComboBoxSample");
    Scene scene = new Scene(new Group(), 450, 250);

    TextField notification = new TextField();

    final ContextMenu contextMenu = new ContextMenu();
    contextMenu.setOnShowing((WindowEvent e) -> {
        System.out.println("showing");
    });
    contextMenu.setOnShown((WindowEvent e) -> {
        System.out.println("shown");
    });

    MenuItem item1 = new MenuItem("About");
    item1.setOnAction((ActionEvent e) -> {
        System.out.println("About");
    });
    MenuItem item2 = new MenuItem("Preferences");
    item2.setOnAction((ActionEvent e) -> {
        System.out.println("Preferences");
    });
    contextMenu.getItems().addAll(item1, item2);

    notification.setContextMenu(contextMenu);
  
    
    
    
    GridPane grid = new GridPane();
    grid.setVgap(4);
    grid.setHgap(10);
    grid.setPadding(new Insets(5, 5, 5, 5));
    grid.add(new Label("To: "), 0, 0);
    grid.add(notification, 2, 3);
    Text text = new Text();
        text.setId("fancytext");
        text.setStyle("#fancytext {-fx-fill: white;-fx-font: 120px Harlow; }");
        text.setX(20);
        text.setY(150);
        
        grid.add(text, 3, 2);
    
    final String cssDefault = "-fx-border-color: blue;\n"
            +"-fx-background-color: black;"
                + "-fx-border-insets: 5;\n"
                + "-fx-border-width: 3;\n"
                + "-fx-border-style: dashed;\n";
//grid.setStyle("-fx-background-color: black;");
    
    
  
    
    
    grid.setStyle(cssDefault);
    Group root = (Group) scene.getRoot();
 
    
    root.getChildren().add(grid);
    
    
    
    
    
        scene.setFill(null);
        
        String cssFile1 = this.getClass().getResource("x.css").toExternalForm();
        String cssFile2 = this.getClass().getResource("Styles.css").toExternalForm();
        String cssFile3 = this.getClass().getResource("/cssStyles/base.css").toExternalForm();
        scene.getStylesheets().addAll(cssFile1, cssFile2, cssFile3);
    stage.setScene(scene);
    stage.show();

  }
  
}

 

posted on 2015-08-11 14:37  rojas  阅读(387)  评论(0编辑  收藏  举报