【问题标题】:How to make TabPane borders green如何使 TabPane 边框变为绿色
【发布时间】:2019-02-02 18:06:32
【问题描述】:

我实现了 JavaFX 教程中的拖放示例。

当我将标签拖到目标 TabPane 上时,我设法添加了效果:

tabPane.setOnDragEntered(new EventHandler<DragEvent>() {
            @Override
            public void handle(DragEvent event) {
                /* the drag-and-drop gesture entered the target */
                /* show to the user that it is an actual gesture target */
                if (event.getGestureSource() != tabPane
                        && event.getDragboard().hasString()) {
                    tabPane.setCursor(Cursor.MOVE);


                    tabPane.setEffect(new Glow());
                }

                event.consume();
            }
        });

        tabPane.setOnDragExited(new EventHandler<DragEvent>() {
            @Override
            public void handle(DragEvent event) {
                /* mouse moved away, remove the graphical cues */
                tabPane.setCursor(Cursor.DEFAULT);

                tabPane.setEffect(null);

                event.consume();
            }
        });

但我想将目标 TabPane 的边框设为绿色,而不是添加 Glow 效果。这可能吗?

【问题讨论】:

    标签: javafx-2 javafx javafx-8


    【解决方案1】:

    您可以在TabPane上设置样式(之后设置为空字符串):

     tabPane.setStyle("-fx-padding: 1; -fx-background-color: green, -fx-control-inner-background; -fx-background-insets: 0, 1;");
    

    如果你想变得很酷,你可以在 CSS 样式表中完成所有操作(并在开始拖动时将 styleClass“dragTab”添加到所有选项卡窗格中(并删除当拖动结束时)。它至少消除了两个鼠标侦听器。

    .dragTab:hover {
        -fx-padding: 1; 
        -fx-background-color: green, -fx-control-inner-background; 
        -fx-background-insets: 0, 1;
    }
    

    【讨论】:

      【解决方案2】:

      这对我有用:

      tabPane.setStyle("-fx-border-style:solid; -fx-padding: 1; -fx-background-color: green;");
      

      或为 -fx-border-style 属性使用其他可能的值,例如 double,dashed , ...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多