解决这一问题的一个途径是将一个新的假州列入<条码>-SplitPane(当分裂者处于ging不平时)。 并且将这种状态与 h制状态相同。
The general idea is to set a custom pseudo state on mouse pressed filter and remove the state on mouse released. Setting the pseudo state on SplitPane will set on the divider as well, so you can set the style specifically for .split-pane-divider:pressed
.
如下文所示:
import javafx.application.Application;
import javafx.css.PseudoClass;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class SplitPaneResizeIssueDemo extends Application {
private final PseudoClass PRESSED_PSEUDOCLASS = PseudoClass.getPseudoClass("pressed");
public static final String CSS = "data:text/css," + // language=CSS
"""
.split-pane:vertical > .split-pane-divider {
-fx-background-color: transparent;
}
.split-pane:vertical > .split-pane-divider:hover,
.split-pane:vertical > .split-pane-divider:pressed{
-fx-background-color: lightblue;
}
""";
public static void main(final String... a) {
Application.launch(a);
}
@Override
public void start(final Stage primaryStage) throws Exception {
StackPane root = new StackPane(buildSplitPane());
final Scene scene = new Scene(root, 300, 400);
scene.getStylesheets().add(CSS);
primaryStage.setScene(scene);
primaryStage.setTitle("SplitPane " + System.getProperty("javafx.runtime.version"));
primaryStage.show();
}
private SplitPane buildSplitPane() {
final SplitPane splitPane = new SplitPane();
splitPane.setStyle("-fx-background-color:yellow;");
splitPane.setPadding(new Insets(15));
splitPane.setOrientation(Orientation.VERTICAL);
splitPane.setDividerPositions(.60);
splitPane.addEventFilter(MouseEvent.MOUSE_PRESSED, e -> splitPane.pseudoClassStateChanged(PRESSED_PSEUDOCLASS, true));
splitPane.addEventFilter(MouseEvent.MOUSE_RELEASED, e -> splitPane.pseudoClassStateChanged(PRESSED_PSEUDOCLASS, false));
StackPane top = new StackPane();
top.setMinSize(100, 10);
top.setStyle("-fx-border-width:1px;-fx-border-color:black;-fx-border-style:solid;-fx-background-color:white;");
StackPane bottom = new StackPane();
bottom.setMinSize(100, 10);
bottom.setStyle("-fx-border-width:1px;-fx-border-color:black;-fx-border-style:solid;-fx-background-color:white;");
splitPane.getItems().addAll(top, bottom);
HBox.setHgrow(splitPane, Priority.ALWAYS);
return splitPane;
}
}
<>说明: 也许会为Button()设定一个更为独特的假名,因为pressed
已经存在。