【问题标题】:Javafx pickOnBounds setting fails with SplitPane - can't click thru a transparent SplitPaneJavafx pickOnBounds 设置因 SplitPane 失败 - 无法通过透明的 SplitPane 单击
【发布时间】:2016-09-09 00:58:55
【问题描述】:

当我有一个透明的 SplitPane 时,设置 pickOnBounds=false 不起作用,我无法单击 splitpane 后面的按钮。 我有一个带有透明 VBox 的 splitPane,pickOnBounds=false 我还使用pickOnBounds = false设置了splitpane,但是鼠标单击不会通过它们下方的按钮。

我在顶部有一个按钮,部分被 SplitPane 覆盖, 底部有按钮可以打开/关闭鼠标透明度和pickOnBounds。

当“启用鼠标透明”未选中时, 并且 'Enable Pick On Bounds' 没有被选中,那么你应该可以点击 SplitPane 后面的按钮,但是你不能。image of app

会不会是Splitpane的skinclass没有继承pickOnBounds设置???

这里是说明问题的示例代码:

package  splitpaneprob;

import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.SplitPane;
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

// Demonstrates the JavaFX node mouseTransparent and pickOnBounds properties.
// shows that 'PickOnBounds=false' does not work for a SplitPane that has a transparent background and you want mouseclicks to go thru
public class PickOnBoundsFails extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        ToggleButton testButton = new ToggleButton("");

        VBox layer1 = new VBox();
        layer1.getChildren().add(testButton);

        SplitPane layer3 = new SplitPane();
        layer3.setMaxWidth(140);

        layer3.setOrientation(Orientation.VERTICAL);
        layer3.setStyle("-fx-background-color:transparent;-fx-border-color:teal");
        layer3.setPrefWidth(120);
        VBox topItem = new VBox();
        topItem.setPickOnBounds(false);
        topItem.setPrefHeight(100);
        topItem.setAlignment(Pos.BOTTOM_LEFT);
        Button topButton = new Button();
        topButton.setMouseTransparent(false);
        topItem.getChildren().add(topButton);
        VBox bottomItem = new VBox();
        Button bottomButton = new Button("click me");
        bottomItem.getChildren().add(bottomButton);
        layer3.getItems().add(topItem);
        layer3.getItems().add(bottomItem);

        StackPane stack = new StackPane();

        stack.getChildren().setAll(layer1, layer3);
        stack.setStyle("-fx-background-color: azure;");

        VBox layout = new VBox();
        layout.getChildren().setAll(
                stack,
                createControls(testButton, layer3, topButton)
        );

        stage.setScene(new Scene(layout));
        stage.show();
    }

    private VBox createControls(ToggleButton controlledButton, SplitPane controlledNode, Button buttonOnSplitPane) {
        controlledButton.textProperty().bind(
                Bindings
                .when(controlledNode.mouseTransparentProperty()).then("Completely Clickable")
                .otherwise(Bindings
                        .when(controlledNode.pickOnBoundsProperty()).then("Partially clickable")
                        .otherwise("Should Be fully Clickable")
                )
        );
        buttonOnSplitPane.textProperty().bind(
                Bindings
                .when(controlledNode.mouseTransparentProperty()).then("NOT Clickable")
                .otherwise("Clickable")
        );
        CheckBox enableMouseTransparency = new CheckBox("Enable MouseTransparency on ScrollPane");
        enableMouseTransparency.setSelected(controlledNode.isMouseTransparent());
        controlledNode.mouseTransparentProperty().bind(enableMouseTransparency.selectedProperty());

        CheckBox enablePickOnBounds = new CheckBox("Enable Pick On Bounds on ScrollPane");
        enablePickOnBounds.setSelected(controlledNode.isPickOnBounds());
        controlledNode.pickOnBoundsProperty().bind(enablePickOnBounds.selectedProperty());

        VBox controls = new VBox(10);
        controls.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;");
        controls.getChildren().addAll(
                enableMouseTransparency,
                enablePickOnBounds
        );

        return controls;
    }
}

【问题讨论】:

    标签: javafx mouseevent transparency splitpane


    【解决方案1】:

    我知道我晚了 5 年,但我只是在同一问题上花了一个上午。

    我认为真正的问题是-fx-background-color:transparent;,如果你删除它,那么你应该有想要的行为。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      • 2018-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-05
      相关资源
      最近更新 更多