javafx笔记

作者: 岁月静好忄 | 来源:发表于2020-03-18 09:57 被阅读0次

    记录javafx使用

    表格样式重写
    .table-view{
       -fx-background-color: transparent;
    }
    
    .table-view:focused{
        -fx-background-color: transparent;
    }
    /*表头样式*/
    .table-view > .column-header-background{
       -fx-background-color: #ffffff;
    }
    
    .table-view .column-header-background .label{
        -fx-background-color: transparent;
    }
    
    .table-view .column-header {
        -fx-background-color: transparent;
    }
    
    .table-view .column-header .label{
        -fx-alignment: center-left;
        -fx-font-family: "Arial";
        -fx-text-fill: rgba(68,68,68,0.96);
        -fx-font-size: 12;
    }
    
    /*设置行*/
    .table-row-cell{
        -fx-cell-size: 35px;
        -fx-alignment: center;
        -fx-border-color: white;
    }
    
    .table-row-cell:hover{
        -fx-background-color: rgb(221,253,253);
    }
    
    .table-row-cell:selected
    {
        -fx-background-color: rgb(210,233,255);
        -fx-text-fill: rgb(0,0,0);
        -fx-border-color: white;
    }
    
    .table-row-cell:selected .label
    {
        -fx-text-fill: rgb(0,0,0);
    }
    
    .table-row-cell:selected .table-cell{
        -fx-text-fill: #000000;
    }
    
    /*设置列*/
    .table-column{
      -fx-alignment: center-left;
      -fx-border-width: 0;
    }
    
    
    
    .table-view > .virtual-flow > .scroll-bar:vertical,
    .table-view > .virtual-flow > .scroll-bar:vertical > .track,
    .table-view > .virtual-flow > .scroll-bar:vertical > .track-background, 
    .table-view > .virtual-flow > .scroll-bar:horizontal,
    .table-view > .virtual-flow > .scroll-bar:horizontal > .track,
    .table-view > .virtual-flow > .scroll-bar:horizontal > .track-background {
        -fx-background-color: transparent;
    }
    
    其他css
    /*去掉边框*/
    {
         -fx-background-insets:0;
         -fx-padding:0;
    }
    /*边框设置*/
    {
        -fx-border-style: solid inside;
        -fx-border-width: 2;
        -fx-border-color: #4c4c4c;
    }
    /*去滚动面板背景*/
    #mainScrollPane > .viewport {
        -fx-background-color: transparent;
    }
    
    #mainScrollPane {
        -fx-background-color: transparent;
    }
    
    /*制作图片背景*/
    #closeLab{
        -fx-pref-height: 22px;
        -fx-pref-width: 22px;
        -fx-background-image: url("../images/dataclose.png");
        -fx-background-repeat: no-repeat;
    }
    /*字体*/
    .root {
        -fx-text-fill: white;
        -fx-font-family: "Microsoft YaHei";
    }
    
    /*复选框的替代标记*/
    /*该-fx-shape属性为标记设置新的SVG路径,-fx-background-color属性定义其颜色*/
    .check-box .mark {
        -fx-shape:
    "M2,0L5,4L8,0L10,0L10,2L6,5L10,8L10,10L8,10L5,6L2,10L0,10L0,8L4,5L0,2L0,0Z";
    }
    .check-box:selected .mark {
        -fx-background-color: #0181e2;
    }
    /*按钮设置*/
    .button {
        -fx-background-color: red;
        -fx-text-fill: white;
        -fx-font-family: "Microsoft YaHei";
        -fx-font-size: 16.0px;
        -fx-border-radius: 4;
        -fx-background-radius: 4;
    }
    /*表格*/
    .table-row-cell:selected {
        -fx-background-color: CSS_TABLE_ROW_CELL_SELECTED_COLOR;
    }
    .table-view .table-cell:last-visible {
        -fx-border-width: 1;
        -fx-border-color: transparent transparent white transparent;
    }
    .table-view .scroll-bar:horizontal {
        -fx-scale-x: 0.999999;
        -fx-scale-y: 0.9;
    }
    .table-view .scroll-bar:vertical {
        -fx-scale-x: 0.9;
        -fx-scale-y: 0.999999;
    }
    
    /*其他字段记录*/
    {
      -fx-alignment: CENTER;
      -fx-text-alignment: center;
      -fx-text-fill: white;
      -fx-min-width: 15;
      -fx-min-height: 15;
      -fx-max-width: 15;
      -fx-max-height: 15;
      -fx-background-insets: 0.0 0.0 0.0 0.0, 0.0;
      -fx-background-radius: 0 5 5 0;
      -fx-background-color: linear-gradient(to bottom, #29292B 0%, #37393B 10%, #444548 30%, #333335
            85%, #DCDCDCBB 90%, #242425 90.3%, #303131 100%);
      -fx-graphic: "/images/fx/icon/DateTimePickerOpenPopup.png";
      -fx-spacing:5;
      -fx-padding: 4 0 4 8;
      -fx-rotate: 180;
      -fx-opacity: 0.9;
      -fx-wrap-text: true;
      -fx-base: transparent;
      -fx-scale-x: 0.8;
      -fx-background-insets: 2 10 2 5;
    }
    
    事件监听
    imgv1.addEventHandler(MouseEvent.MOUSE_EXITED, new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event)
                    {
                        System.out.println("鼠标移出监听");
                    }
                    
                });
    
    textField.focusedProperty().addListener(
        new ChangeListener<Boolean>() {
              @Override
              public void changed(ObservableValue<? extends Boolean> arg0,Boolean arg1, Boolean arg2) {
                if(arg2==false)
                {
                      System.out.println("失去焦点监听");
                }
              }
        }
    );
    
    布局
    //地址:http://www.javafxchina.net/blog/2015/06/doc05_buildinlayout/
    
    //边框布局,上下左右中间四块区域
    BorderPane border = new BorderPane();
    border.setTop(...);
    border.setLeft(...);
    border.setCenter(...);
    border.setRight(...);
    border.setBottom(...);
    
    //水平盒子
    HBox hbox = new HBox();
    hbox.setPadding(new Insets(15, 12, 15, 12)); //节点到边缘的距离
    hbox.setSpacing(10); //节点之间的间距
    hbox.setStyle(“-fx-background-color: #336699;”); //背景色
    
    //垂直盒子
    VBox vbox = new VBox();
    vbox.setPadding(new Insets(10)); //内边距
    vbox.setSpacing(8); //节点间距
    
    //堆栈面板
    StackPane stack = new StackPane();
    stack.getChildren().addAll(helpIcon, helpText);
    stack.setAlignment(Pos.CENTER_RIGHT); //右对齐节点
     
    //网格面板
    GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(0, 10, 0, 10));
    // 将category节点放在第1行,第2列
    grid.add(category, 1, 0);
    // 将chartTitle节点放在第1行,第3列
    grid.add(chartTitle, 2, 0);
    // 将chartSubtitle节点放在第2行,占第2和第3列
    grid.add(chartSubtitle, 1, 1, 2, 1);
     // 将House图标放在第1列,占第1和第2行
     grid.add(imageHouse, 0, 0, 1, 2);
    // 将左边的标签goodsPercent放在第3行,第1列,靠下对齐
    GridPane.setValignment(goodsPercent, VPos.BOTTOM);
    grid.add(goodsPercent, 0, 2);
    // 将饼图放在第3行,占第2和第3列
    grid.add(imageChart, 1, 2, 2, 1);
    // 将右边的标签servicesPercent放在第3行,第4列,靠上对齐
    GridPane.setValignment(servicesPercent, VPos.TOP);
    grid.add(servicesPercent, 3, 2);
    
    //流面板
    FlowPane flow = new FlowPane();
    flow.setPadding(new Insets(5, 0, 5, 0));
    flow.setVgap(4);
    flow.setHgap(4);
    flow.setPrefWrapLength(170); // 预设FlowPane的宽度,使其能够显示两列
    
    //磁贴面板
    TilePane tile = new TilePane();
    tile.setPadding(new Insets(5, 0, 5, 0));
    tile.setVgap(4);
    tile.setHgap(4);
    tile.setPrefColumns(2);
    
    //锚面板
    AnchorPane anchorpane = new AnchorPane();
    }
    

    相关文章

      网友评论

        本文标题:javafx笔记

        本文链接:https://www.haomeiwen.com/subject/mxzfyhtx.html