码迷,mamicode.com
首页 > 编程语言 > 详细

javafx style and cssFile

时间:2015-08-11 15:42:48      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

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

  }
  
}

 

javafx style and cssFile

标签:

原文地址:http://www.cnblogs.com/rojas/p/4720957.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!