0
我使用某些事件在HBox上放置小矩形。當窗口沒有被調整大小時,它們的位置是完美的,但是當你從小屏幕到全屏時,它們的位置是錯誤的(當然,因爲它們在放置時獲得了X的一定值 - 這通過獲得在特定時刻HBox的寬度)。HBox上的Java節點動態位置
問:
我怎樣才能使這些位置動態的,所以當我調整窗口的大小,他們留在比例是多少?
圖片:
代碼:
@FXML HBox tagLine; // initializes the HBox
...
public void addTag(String sort) {
Rectangle rect = new Rectangle(20, tagLine.getHeight());
double pos = timeSlider.getValue()/100 * tagLine.getWidth(); // retrieves position at the moment of being called
rect.setTranslateX(pos);
rect.setOnMouseEntered(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
showNotification("Gemarkeerde gebeurtenis: " + sort);
}
});
rect.setOnMouseExited(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
notificationHide.play();
}
});
tagLine.getChildren().add(rect);
}
你如何定位在HBox中的矩形?保證金?把節點放在它的左邊? 'translateX'? – fabian
您需要向我們展示一些代碼。只需編輯您的問題並添加您當前用於翻譯矩形的邏輯。 – ItachiUchiha