小编Min*_*Brc的帖子

将鼠标悬停在 javafx 中的图像节点上时无法获得正确的颜色

当我将鼠标悬停在图像上我在图像的某些像素中得到了错误的颜色值,这似乎是一种像素移位。

我在ImageView上使用MouseMoved事件来获取图像上光标的x 和 y坐标,然后使用这些坐标中的颜色创建一个Color实例。最后,我使用该颜色填充 Circle 节点。

我想知道为什么它返回某些像素的错误颜色值。

PS:我在 png 和 jpeg 图像上尝试过,但同样的事情发生了。

这是控制器的初始化方法,我将事件侦听器设置为ImageView

 @FXML
    public ImageView inputImage;

    public void initialize() {

        inputImage.setOnMouseMoved(event -> {
            int xPosition = (int) event.getX();
            int yPosition = (int) event.getY();

            Color pixelColor = inputImage.getImage().getPixelReader().getColor(xPosition, yPosition);

            circleColor.setFill(pixelColor);
        });
    }
Run Code Online (Sandbox Code Playgroud)

FXML文件的一部分:

            <VBox HBox.hgrow="ALWAYS" alignment="CENTER">
                <HBox alignment="CENTER">
                    <VBox.margin>
                        <Insets bottom="50.0"/>
                    </VBox.margin>

                    <ImageView fx:id="inputImage" pickOnBounds="true" preserveRatio="true" fitHeight="300"
                               fitWidth="300">
                        <Image …
Run Code Online (Sandbox Code Playgroud)

java javafx image colors

3
推荐指数
1
解决办法
172
查看次数

避免输入溢出容器并在调整大小时让它们跳到下一行

当我添加太多输入(取决于我想要多少)时,它们会溢出它们的容器,例如当我只有两个输入时,它们会在我调整窗口大小时溢出容器。

这是我的 html 和 css:

#datails_container {
    position: relative;
    display: flex;
    background-color: darkgrey;
    width: 70%;
    height: 550px;
    border-radius: 5px;
    top: 50px;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
    background-color: black;
    border-radius: 6px;
}

.theight {
    height: 26%;
    border: 1px black solid;
    margin: auto;
    display: flex;
    width: 80%;
    background-color: white;
    border-radius: 4px;
}

form {
    width: 100%;
    height: 100%;
    align-items: center;
    display: flex;
    flex-flow: row wrap;
    justify-content: space-between;
}

span {
    background-color: #b50612;
    width: 92px;
    height: min-content;
    border-radius: 5px;
    position: …
Run Code Online (Sandbox Code Playgroud)

html javascript css

1
推荐指数
1
解决办法
104
查看次数

一个控制多个点击监听器

我正在使用答案CustomButton中的自定义切换按钮。正如您在构造函数中看到的,单击侦听器将设置为按钮和对象本身。在主控制器类中,我创建了它的一个实例并设置了一个鼠标单击事件侦听器,以便根据其状态更新 UI,但这导致了一种奇怪的行为,在某些单击时,按钮会切换并更改颜色,有时用户界面将更新...

这就是我在MainController中创建和添加点击侦听器的方式:

filterSwitchButton = new SwitchButton();
    filterSwitchButton.setId("filterSwitchButton");
    HBox.setMargin(filterSwitchButton, new Insets(0, 20, 0, 50));
    filterSwitchButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            // update UI
        }
    });
Run Code Online (Sandbox Code Playgroud)

如何更新 UI 并更改单击切换按钮时的状态?

java user-interface javafx

0
推荐指数
2
解决办法
88
查看次数

标签 统计

java ×2

javafx ×2

colors ×1

css ×1

html ×1

image ×1

javascript ×1

user-interface ×1