2016-10-18 6 views
0

私はjavafxでパネルを作ろうとしていますが、私はメインペインとして境界枠に慣れていました。中央パネルには4つのウィンドウ(main1、main2、main3、main4)があり、左パネルにはナビゲーションメニューがあります。javaFx borderPaneのLeftPaneからCenterPaneを変更するにはどうすればよいですか?

borderPane.setCenter(mainMenu1.getCenterMain1UI()); 
//borderPane.setCenter(mainMenu2.getCenterMain2UI()); 
//borderPane.setCenter(mainMenu3.getCenterMain3UI()); 
//borderPane.setCenter(mainMenu4.getCenterMain4UI()); 


public BorderPane getAppWindow(){ 

    if (borderPane == null){ 

     borderPane = new BorderPane(); 
     borderPane.setTop(topPanel.getTopPanelUI()); 
     borderPane.setBottom(bottomPanel.getBottomPanelUI()); 
     borderPane.setLeft(leftPanel.getLeftPanelUI()); 

     borderPane.setCenter(mainMenu.getCenterMainUI()); 
     borderPane.setAlignment(borderPane.getCenter(), Pos.TOP_LEFT); 

    } 

    return borderPane; 
} 
左側のパネルコントローラで

public class LeftPanelController { 

     public VBox leftPanelPane; 

     public Button btnLeftPanelMainmenu; 
     public Button btnLeftPanelDb; 
     public Button btnLeftPanelOfficeInfo; 
     public Button btnLeftPanelConfiguration; 



     public void btnLeftPanelMainmenuOnClickAction(ActionEvent e){ 
      change border pane center to main 
     } 

     public void btnLeftPanelDbOnClickAction(ActionEvent e){ 
      change border pane center to DB 
     } 

     public void btnLeftPanelOfficeInfoOnClickAction(ActionEvent e){ 
      change border pane center to DB 
     } 

     public void btnLeftPanelConfigurationOnClickAction(ActionEvent e){ 
      change border pane center to configuration 
     } 

    } 
+0

コードを3回(コードを呼び出す前に 'center'が' null'でなかった場合は4回)置き換えます。左側のパネルとのやりとりで 'center 'を一度置き換えてみてください。 – fabian

+0

実際の質問が私には本当に不明です。左パネルの 'Button'sのクリックハンドラに投稿したコードラインの1つを呼び出しますか? – DVarga

答えて

0

私はそのような左側のパネルで、私のボタンのクリック方法を変更。

0

それはBorderPaneの中央に表示される内容変化するようにあなたのメニューボタンごとにアクションイベントに設定する必要があります。

ここでは例です:

import java.util.LinkedHashMap; 
import java.util.Map; 
import javafx.application.Application; 
import javafx.event.ActionEvent; 
import javafx.event.EventHandler; 
import javafx.scene.Node; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.Label; 
import javafx.scene.layout.*; 
import javafx.stage.Stage; 

public class BorderPaneExample extends Application { 

    private Map<String, Node> menuOptions; 
    private Node defaultCenterNode = new Label("Example node 1"); 

    @Override 
    public void start(Stage primaryStage) throws Exception { 

     menuOptions = new LinkedHashMap<>(); 
     menuOptions.put("Main Menu", defaultCenterNode); 
     menuOptions.put("History", new Label("Example node 2")); 
     menuOptions.put("Office Info", new Label("Example node 3")); 
     menuOptions.put("Configuration", new Label("Example node 4")); 
     BorderPane root = new BorderPane(); 
     root.setCenter(defaultCenterNode); 
     VBox menuLayout = new VBox(); 

     for (String key : menuOptions.keySet()) { 
      Button button = new Button(key); 
      button.setMaxWidth(Double.MAX_VALUE); 
      button.setOnAction(new EventHandler<ActionEvent>() { 

       @Override 
       public void handle(ActionEvent event) { 
        root.setCenter(menuOptions.get(key)); 
       } 
      }); 
      menuLayout.getChildren().add(button); 
     } 

     root.setLeft(menuLayout); 

     Scene scene = new Scene(root, 800, 600); 

     primaryStage.setScene(scene); 
     primaryStage.setTitle("BorderPane Example"); 
     primaryStage.setResizable(false); 
     primaryStage.sizeToScene(); 
     primaryStage.show(); 

    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 
+0

あなたは正しいですが、私のmainStage、leftPanelとcenterPanelは別のディレクトリにあります。私は階層に関するスクリーンショットをpdfしました。 –

+0

@enesクラスについて多くのことを知らずに、コメントするのは難しいです。しかし、 'Node'を拡張すると仮定すると、私が提供した例の' Label'のように、それらのクラスの新しいインスタンスを作ることができます。 –

+0

おかげさまで、すべてのコンポーネントが中央のアンカーペインです。左にvboxがあります。すべてのパネルを呼び出すappWindowに関する新しいイメージを更新しました。 –

関連する問題