2014-12-05 2 views
2

내 ScalaFX 8 응용 프로그램의 기본 레이아웃은 BorderPane입니다. top 속성에는 메뉴가 포함되어 있고 bottom에는 상태 표시 줄과 비슷한 것이 있습니다. 내 목표는 BorderPane의 center (SubScene)에서 3D 오브젝트를보기위한 구성 요소를 표시하는 것입니다.ScalaFX의 BorderPane 중심에 하위 스코프 추가

stage = new PrimaryStage { 
    scene = new Scene(900, 900, true, SceneAntialiasing.Balanced) { 
    root = new BorderPane { 
     top = createMenu // creates a menu inside of a VBox 
     center = createViewer // should create a subscene inside of whatever is needed 
     bottom = createStatusBar // creates a status bar inside of a VBox 
    } 
    } 
} 

검은 색 배경과 간단한 구로만 구성된 하위 윤곽으로 최소한의 작업 예제를 만들려고합니다. SubScene은 BorderPane의 가운데에서 사용 가능한 전체 공간을 사용하고 그에 따라 크기를 조정해야합니다. 불행히도, 나는 그것을 작동하게 만들 수 없습니다.

SubScene의 크기가 고정되어 있으므로 SubScene을 다른 컨테이너 (자동으로 크기를 조정할 수 있음)에 삽입하고 SubScene의 치수를 주변의 컨테이너 크기에 바인딩해야한다고 가정합니다.

def createViewer = { 
    val bp = new BorderPane 
    val subScene: SubScene = new SubScene(bp, 200, 200, true, SceneAntialiasing.Balanced) { 
    fill = Color.Black 
    width <== bp.width 
    height <== bp.height 
    content = new Sphere(3) { material = new PhongMaterial(Color.Red) } 
    camera = new PerspectiveCamera(true) { ... } 
    } 
    bp.center = subScene 
    subScene 
} 

결과는 다음과 같습니다

enter image description here

두 명백한 문제 :

  • SubScene는 생성자에서 고정 된 크기를 유지합니다. 안에서는 외부 BorderPane의 중앙에 "극대화 없다", 나 윈도우가 빨간 점이지만, SubScene의 오른쪽 하단 모서리에 검은 아니다
  • 크기가 조정됩니다 때 아무것도하지 않는 (?)

내 가정은 SubScene의 루트 요소가 실제로 무엇인지, 어떤 역할을하는지 이해하는 데 약간의 문제가 있다는 것입니다. another thread for JavaFX with a similar problem을 찾았습니다.이 솔루션은 SubScene의 루트 요소 (해당 요소의 출처가 확실하지 않습니다)와 창을 구별합니다.하지만이 정보를 제 경우에 적용 할 수 없습니다. 어떤 도움을 주셔서 감사합니다. 감사.

답변

0

여기에 아이디어는 거기에이 일을 더 우아한 방법은 아마도,하지만 여기에

scene = new Scene(900, 900, true, SceneAntialiasing.Balanced) { 
    // these are read only properties for the scene 
    var tmpw = this. width 
    var tmph = this. height 

    root = new BorderPane { 

    top = new HBox { 
     content = new Label { 
     text = "menu" 
     } 
    } 

    center = createView(tmpw, tmph) 

    } 
} 
    width onChange show 
    height onChange show 

}

아이디어를 작동하는 것입니다 최상위 장면의 읽기 전용 속성을 가져 read only 속성을 subscene의 속성에 바인드하면 subscene이 'this'키 워드를 피하는 방법 일 가능성이 있습니다. 이 장면과 하위 장면 크기를 부모 장면과 함께 테스트했습니다. PerspectiveCamera 코드 블록을 사용하지 않으므로 생략했습니다.

def createView(boundWidth : ReadOnlyDoubleProperty, boundHeight : ReadOnlyDoubleProperty):   BorderPane = { 

    new BorderPane { 

     center = new SubScene(boundWidth.get(), boundHeight.get(), true, SceneAntialiasing.Balanced) { 
     fill = Color.BLACK 
     content = new Sphere(3) { material = new PhongMaterial(Color.RED) } 
     camera = new PerspectiveCamera(true) 
     // bind the subscene properties to the parents 
     this.width.bind(boundWidth.add(-200)) 
     this.height.bind(boundHeight.add(-200)) 
    } 

    } 

} 
+0

감사합니다. 마지막으로 두 가지 질문 : 1. SubScene의 크기를 BorderPane의 중심 크기에 바인딩하는 방법이 없습니다 (대신 장면 크기를 사용했지만 괜찮습니다). 2. 첫 번째 발췌 문장의 마지막 두 줄은 무엇입니까 (... onchange show)? 우연히, 나는 그들을 붙여 넣지 않았다. 그러나 당신의 솔루션은 어쨌든 작동 할 것 같다. – fxfour

+0

fxfour, 당신이 게시 한 원래 코드는 크기가 변하지 않았고 극복 할 첫 번째 문제였다. 나는이 키워드를 사용하여 행복하지 않다. 'this'밖에서이 일을 할 수있는 방법이되어야합니다. this.width는 범위의 노드 인 ReadOnlyProperty를 가져옵니다. BorderPane의 중심 바인딩 크기를 시도한 것처럼 작동하지 않습니다.'width onChange show'를 사용하면 장면 크기를 조정할 수 있으며 바인딩을 통해 새 치수를 subscene에 전달합니다. ReadOnlyProperty를 게으른 평가판을 통해 얻을 수있는 더 좋은 방법을 찾으면 대답을 업데이트 할 것입니다. –

+0

나는 그것을 얻는다, 다시 당신에게 감사해라! – fxfour

관련 문제