문제

I have a Pane within my interface. On that Pane I add Shape objects and drag them around. I what to make my Pane bigger when one Shape reaches the visual bounds of the Pane. As a prototype, I try to make it bigger whenever I click my mouse. The Pane is child (within) a ScrollPane. Here is my code:

    paneArea.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            System.out.println(paneArea.getWidth()+" "+paneArea.getHeight());
            paneArea.resize(paneArea.getWidth() + 100, paneArea.getHeight() + 100);                
            System.out.println(paneArea.getWidth()+" "+paneArea.getHeight());
        }
    });

When I click twice I get the following result:

602.0 574.0
702.0 674.0
602.0 574.0
702.0 674.0

So the Pane basically resizes briefly and then returns to its original size.On the FXML, the max height and width are set to USE_PREF_SIZE as well as MAX_VALUE. I also tried to increase maxWidth/height before calling resize but made no difference. Any advice?

도움이 되었습니까?

해결책

I have been using wrong method as well as fxml option. The way to do it was with setPrefSize method, and then set the max size at USE_PREF in fxml file.

다른 팁

Your code is wrong. Instead of using

paneArea.resize(paneArea.getWidth() + 100, paneArea.getHeight() + 100); 

use

paneArea.setPrefWidth(paneArea.getWidth() + 100) ; 
paneArea.setPrefHeight(paneArea.getHeight)() + 100) ;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top