zoukankan      html  css  js  c++  java
  • 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;
    "
                +"-fx-background-color: black;"
                    + "-fx-border-insets: 5;
    "
                    + "-fx-border- 3;
    "
                    + "-fx-border-style: dashed;
    ";
    //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();
    
      }
      
    }
  • 相关阅读:
    流程控制之if判断
    各种运算符
    输入和输出
    垃圾回收机制(详细)
    3/5 作业
    3/4 作业
    数据类型
    变量
    Checkout 显示 URL /../../.. 不存在
    Tomcat8 访问 manager App 失败
  • 原文地址:https://www.cnblogs.com/rojas/p/4720957.html
Copyright © 2011-2022 走看看