깨끗한 방법은 없지만 SplitPane
에서 CSS lookup을 사용하는 것이 가능합니다.
디바이더는 CSS 클래스가 split-pane-divider
이므로 장면 그래프에서 나누기를 얻을 수 있으며 실제로는 StackPane
인스턴스입니다.
이 StackPane
에서 마우스 누름 및 마우스 놓기 이벤트 리스너를 등록하고 해당 구분선이 현재 "드래그 중"임을 나타내는 클래스 멤버를 업데이트 할 수 있습니다. 그리고 position 속성 리스너에서이 클래스 멤버를 확인할 수 있습니다. true 일 경우 마우스로 구분선을 이동한다는 것을 의미합니다. 그렇지 않으면 변경 사항을 무시할 수 있습니다.
예 :
public class Main extends Application {
// Indicates that the divider is currently dragged by the mouse
private boolean mouseDragOnDivider = false;
@Override
public void start(Stage primaryStage) throws Exception{
SplitPane sp = new SplitPane();
sp.getItems().addAll(new StackPane(), new StackPane());
sp.setDividerPositions(0.3f);
// Listen to the position property
sp.getDividers().get(0).positionProperty().addListener((obs, oldVal, newVal) -> {
if(mouseDragOnDivider)
System.out.println("It's a mouse drag to pos: " + newVal.doubleValue());
});
primaryStage.setScene(new Scene(sp, 300, 275));
sp.requestLayout();
sp.applyCss();
// For each divider register a mouse pressed and a released listener
for(Node node: sp.lookupAll(".split-pane-divider")) {
node.setOnMousePressed(evMousePressed -> mouseDragOnDivider = true);
node.setOnMouseReleased(evMouseReleased -> mouseDragOnDivider = false);
}
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
참고 레이아웃이 생성되고, CSS가 적용되는 경우에 검색 만 작동하기 때문에, 따라서 requestLayout()
및 applyCss()
방법이 이미 실행하는 것이 중요 (Scene
에 첨부 된) 씬 그래프에 이미 SplitPane
이 추가되어 있습니다.
큰 그림은 무엇입니까? 창의 크기가 변경 될 때마다 슬라이더도 "움직입니다"라고 주장 할 수 있습니다. 왜 사용자가 드래그하는지 알고 싶습니까? –