2016-08-29 10 views
0

노드가있는 Pane을 만들면 화면에 렌더링하지 않고 너비와 높이를 어떻게 계산할 수 있습니까?(JavaFX의) 장면에 추가하지 않고 창 크기를 가져 옵니까?

메모리 (메모리)에 문서를 만들어 프린터로 보내려고합니다. 문제는 내가 얼마나 많은 페이지를 계산할 필요가 있다는 것입니다. 문서의 크기를 알아야합니다.

내가 실험하고있어 빠른 예 :

Label testLabel1 = new Label("TEST1"); 
Label testLabel2 = new Label("TEST no. 2"); 
GridPane testGl = new GridPane(); 
testGl.add(testLabel1, 1, 1); 
testGl.add(testLabel2, 2, 2); 
VBox testVBox = new VBox(testGl); 
Pane testPane = new Pane(testVBox); 

//I read that this might be required 
testPane.applyCss(); 
testPane.layout(); 

//Also that a delay is needed for the fx tread to update testPane 
// (but shouldn't this all be in the same thread since it is in the same function? 
// It doesn't seem to help). 
Platform.runLater(()->{ 
    System.out.println(">>> "+ testPane.getBoundsInLocal().getWidth()); 
}); 

모든 나는 지금까지 출력이 >>> 0.0입니다. 개발중인 프로그램에서 "컨테이너"안에 Pane이 여러 개 있습니다. Pane. 따라서 변수 testPane.

감사합니다.

답변

0

레이아웃을 적용하려면 을 Scene에 추가해야합니다. 그러나 Scene를 표시 할 필요가없고,이 장면에서 Pane을 유지 할 필요가 없다 : 당신이 Scene에서 뿌리를 제거 할 경우 비로 교체해야한다는

Label testLabel1 = new Label("TEST1"); 
Label testLabel2 = new Label("TEST no. 2"); 
GridPane testGl = new GridPane(); 
testGl.add(testLabel1, 1, 1); 
testGl.add(testLabel2, 2, 2); 
VBox testVBox = new VBox(testGl); 
Pane testPane = new Pane(testVBox); 

// add testPane to some scene before layouting 
Scene testScene = new Scene(testPane); 

testPane.applyCss(); 
testPane.layout(); 

System.out.println(">>> " + testPane.getBoundsInLocal().getWidth()); 

// Pane could be removed from scene 
Group replacement = new Group(); 
testScene.setRoot(replacement); 

널 노드.

+0

감사합니다. 저는 항상 Scene의 요소가 시각적 구성 요소 (예 : 영화의 '장면')로 간주됩니다. Scene 객체의 기본 사항도 검토해야합니다. 내 다른 직업 전화 그래서 나는 내일 그것을 테스트해야합니다. –