0
TextArea
은 ScrollPane
입니다. 여기서 ScrollPane
은 TextArea
에서 getParent()
을 5 번 호출하여 찾을 수 있습니다. ScrollPane
에 상대적인 TextArea
의 좌표를 찾는 방법이 있습니까?다른 노드/창에 상대적인 노드의 경계를 가져옵니다.
TextArea
은 ScrollPane
입니다. 여기서 ScrollPane
은 TextArea
에서 getParent()
을 5 번 호출하여 찾을 수 있습니다. ScrollPane
에 상대적인 TextArea
의 좌표를 찾는 방법이 있습니까?다른 노드/창에 상대적인 노드의 경계를 가져옵니다.
이 작업을 수행 할 수 있습니다
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.geometry.Bounds;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class TextAreaBoundsInScrollPane extends Application {
@Override
public void start(Stage primaryStage) {
ScrollPane scrollPane = new ScrollPane();
VBox scrollPaneContent = new VBox(5);
TextArea textArea = new TextArea();
scrollPaneContent.setPadding(new Insets(10));
scrollPaneContent.setAlignment(Pos.CENTER);
scrollPaneContent.getChildren().add(new Rectangle(200, 80, Color.CORAL));
scrollPaneContent.getChildren().add(textArea);
scrollPaneContent.getChildren().add(new Rectangle(200, 120, Color.CORNFLOWERBLUE));
scrollPane.setContent(scrollPaneContent);
BorderPane root = new BorderPane(scrollPane);
root.setTop(new TextField());
root.setBottom(new TextField());
ChangeListener<Object> boundsChangeListener = (obs, oldValue, newValue) -> {
Bounds bounds = scrollPane.sceneToLocal(textArea.localToScene(textArea.getBoundsInLocal()));
System.out.printf("[%.1f, %.1f], %.1f x %.1f %n", bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight());
};
textArea.boundsInLocalProperty().addListener(boundsChangeListener);
textArea.localToSceneTransformProperty().addListener(boundsChangeListener);
scrollPane.localToSceneTransformProperty().addListener(boundsChangeListener);
Scene scene = new Scene(root, 400, 400);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
이이 텍스트 영역의 경계를 찾을 수 있습니다 :
여기에 완벽한 예입니다? 그것은 나를 위해 일하는 것 같지 않습니다. – Vasting
예, 스크롤 영역의 좌표계에서 텍스트 영역의 경계를 제공합니다. –
SSCCE를 추가했습니다. –