2017-12-29 4 views
0

새 프로젝트에서 JavaFX를 사용하고 싶고 아래 스크린 샷과 같은 것을 원합니다.JavaFX 탐색 표시 줄 및 내용 분할 창

왼쪽의 사이트에는 내비게이션 막대가 필요하고 오른쪽에는 내 콘텐츠가 필요합니다. 그래서, 왼쪽에있는 VBox를 사용하고, 오른쪽에 AnchorPane (또는 더 나은 ScrollPane)을 사용합니다.

"보안"버튼을 클릭하면 오른쪽에 내 "보안"장면이로드됩니다. 그러나 어떻게 관리 할 수 ​​있습니까? 이것에 대한 해결책을 찾지 못했습니다.

enter image description here

고마워요

+1

코드 작성을 시도한 대상은 무엇입니까? – Kerry

답변

1

이 내비게이션의 예시적인 구현이다. 여기 view_1.fxml에 설명 된 뷰는 기본적으로로드됩니다

<BorderPane fx:id="mainBorderPane" fx:controller="sample.Controller" xmlns:fx="http://javafx.com/fxml"> 
    <left> 
     <VBox spacing="5"> 
      <Button text="btn 1" onAction="#handleShowView1"/> 
      <Button text="btn 2" onAction="#handleShowView2"/> 
      <Button text="btn 3" onAction="#handleShowView3"/> 
     </VBox> 
    </left> 
    <center> 
     <fx:include source="view_1.fxml"/> 
    </center> 
</BorderPane> 

을 그리고 이것은

public class Controller { 

    @FXML 
    private BorderPane mainBorderPane; 

    @FXML 
    private void handleShowView1(ActionEvent e) { 
     loadFXML(getClass().getResource("/sample/view_1.fxml")); 
    } 

    @FXML 
    private void handleShowView2(ActionEvent e) { 
     loadFXML(getClass().getResource("/sample/view_2.fxml")); 
    } 

    @FXML 
    private void handleShowView3(ActionEvent e) { 
     loadFXML(getClass().getResource("/sample/view_3.fxml")); 
    } 

    private void loadFXML(URL url) { 
     try { 
      FXMLLoader loader = new FXMLLoader(url); 
      mainBorderPane.setCenter(loader.load()); 
     } 
     catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
} 

갱신

이의 의견이 직접 나열되는 변환되는 컨트롤러입니다 FXML 파일

<BorderPane fx:id="mainBorderPane" fx:controller="sample.Controller" xmlns:fx="http://javafx.com/fxml"> 
    <left> 
     <VBox spacing="5"> 
      <Button text="btn 1" userData="/sample/view_1.fxml" onAction="#handleShowView"/> 
      <Button text="btn 2" userData="/sample/view_2.fxml" onAction="#handleShowView"/> 
      <Button text="btn 3" userData="/sample/view_3.fxml" onAction="#handleShowView"/> 
     </VBox> 
    </left> 
    <center> 
     <fx:include source="view_1.fxml"/> 
    </center> 
</BorderPane> 

및 컨트롤러

public class Controller { 

    @FXML 
    private BorderPane mainBorderPane; 

    @FXML 
    private void handleShowView(ActionEvent e) { 
     String view = (String) ((Node)e.getSource()).getUserData(); 
     loadFXML(getClass().getResource(view)); 
    } 

    private void loadFXML(URL url) { 
     try { 
      FXMLLoader loader = new FXMLLoader(url); 
      mainBorderPane.setCenter(loader.load()); 
     } 
     catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
}