gpt4 book ai didi

java - 如何使覆盖 Vbox 节点可点击?

转载 作者:行者123 更新时间:2023-12-02 01:57:03 26 4
gpt4 key购买 nike

我正在尝试构建一个 javafx 修剪器,我已经做到了,但是当我在 ImageViews 上添加 setOnMouseClicked 时,我制作的修剪器隐藏了这些节点,因此未处理该操作。

我已经设置了 Rectangle -50 以便将修剪器覆盖到 ImageView,不幸的是,这个 make 事件不起作用。

Rectangle rectangle = new Rectangle(0, -50, 80, 40);

流动的 Controller 构建是框架

enter image description here

package app.controller;

import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ScrollPane;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

public class Trimmer2 implements Initializable {
private Node selectedNode;
@FXML
private HBox hboxStream;

@FXML
private HBox hboxStreamTrim;

@FXML
private Label lblTime;

public void initialize(URL arg0, ResourceBundle arg1) {
buidTrimmer();
}

private void buidTrimmer() {
ImageView pic = null;
HBox hbox = new HBox();
DropShadow shadow = new DropShadow();
ClassLoader classLoader = getClass().getClassLoader();
File path = new File(classLoader.getResource("streams/sub_stream").getPath());
File [] files = path.listFiles();

Image[] images = new Image[files.length];
ImageView[] pics = new ImageView[files.length];

for (int i = 0; i < files.length; i++) {
final Image image = images[i] =
new Image(files[i].toURI().toString(), 80, 40, false, false);
pic = pics[i] =
new ImageView(image);
pic.setEffect(shadow);
pic.setOnMouseClicked((MouseEvent me) -> {
System.out.println("do action");
});
hbox.getChildren().add(pics[i]);
}



Rectangle rectangle = new Rectangle(0, -50, 80, 40);
rectangle.setFill(Color.rgb(33, 150, 243, 0.5));
Pane pane = new Pane( rectangle );

makeSelectable(rectangle, pane);

VBox vbox = new VBox();
vbox.setSpacing(10);
vbox.getChildren().addAll(hbox,pane);
ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(vbox);
scrollPane.setId("my_scrollPane");

hboxStream.getChildren().add(scrollPane);
}

private void makeSelectable(Node node, Pane root) {

node.setOnMouseClicked(event -> {
if (selectedNode != node) {
root.getChildren().removeIf(candidate -> candidate instanceof ResizingControl);
selectedNode = node;

node.toFront();
ResizingControl resizingControl = new ResizingControl(node);
root.getChildren().add(resizingControl);
}
System.out.println("here");
event.consume();
});

}
}

最佳答案

尝试在 Pane 内添加水平盒和矩形,顺便说一句,该 Pane 必须为空。希望它有帮助:)

    Rectangle rectangle = new Rectangle(0, 0, imgWidth, imgHeight);
rectangle.setFill(Color.rgb(33, 150, 243, 0.35));
Pane pane = new Pane();
VBox vbox = new VBox();
vbox.getChildren().addAll(pane);
pane.getChildren().addAll(hbox,rectangle);

关于java - 如何使覆盖 Vbox 节点可点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52170127/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com