English 中文(简体)
Java 2. 彩色 c
原标题:JavaFX SplitPane Divider hover color css
  • 时间:2024-03-13 19:52:52
  •  标签:
  • css
  • javafx

我想通过CSS向Javaeno的SplitPane Divider分配一张 h色。

I am able to achive this by using the following CSS

.split-pane:horizontal > .split-pane-divider {
    -fx-background-color: transparent;
}
.split-pane:horizontal > .split-pane-divider:hover {
    -fx-background-color: lightblue;
}

然而,由于分裂者落在 cur子后面,它造成了微小的影响,因为每当分裂者赶上 cur子的位置时,就会引发 h,但尽管 slowly慢慢,它却只造成许多微弱。

I want the hover color to be applied throughout any dragging of the divider.

Is there a way to achieve this via CSS? I tried .split-pane-divider:focused and .split-pane-divider:selected, but no luck :(

如果没有,是否有其他办法实现这一目标?

Thanks!

问题回答

解决这一问题的一个途径是将一个新的假州列入<条码>-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.

如下文所示:

“entergraph

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已经存在。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...

热门标签