2013-08-19 22 views
2

垂直菜單我想創建配置面板這樣的例子:的配置面板

enter image description here

的問題是,我不知道如何創建在左側垂直菜單。你能舉一些類似菜單的例子嗎?

+0

重複的:如何在Java桌面應用程序菜單](http://stackoverflow.com/questions/13556637/how-to-have-menus-in-java-desktop-application) – jewelsea

回答

1
package verticalmenubar; 

import javafx.application.Application; 
import javafx.event.ActionEvent; 
import javafx.event.EventHandler; 
import javafx.scene.Scene; 
import javafx.scene.control.Accordion; 
import javafx.scene.control.Button; 
import javafx.scene.control.TabPane; 
import javafx.scene.control.TitledPane; 
import javafx.scene.layout.BorderPane; 
import javafx.scene.layout.Pane; 
import javafx.scene.layout.VBox; 
import javafx.stage.Stage; 

/** 
* 
* @author reegan 
*/ 
public class VerticalMenuBar extends Application { 
    public static TabPane tabPanel; 
    @Override 
    public void start(Stage primaryStage) { 
     BorderPane root = buildView(); 
     Scene scene = new Scene(root, 300, 250);   
     primaryStage.setTitle("Hello World!"); 
     primaryStage.setScene(scene); 
     primaryStage.show(); 
    } 

    BorderPane buildView() { 
     BorderPane root = new BorderPane(); 
     tabPanel = new TabPane(); 
     root.setCenter(tabPanel); 
     Accordion accordion = new Accordion(); 
     Pane pane = null; 
     TitledPane tiledPane; 
     General1Bar general1 = new General1Bar(); 
     pane= general1.getView(); 
     tiledPane = new TitledPane("General1", pane); 
     accordion.getPanes().add(tiledPane); 

     General2Bar general2 = new General2Bar(); 
     pane = general2.getView(); 
     tiledPane = new TitledPane("General2", pane); 
     accordion.getPanes().add(tiledPane); 

     General3Bar general3 = new General3Bar(); 
     pane = general3.getView(); 
     tiledPane = new TitledPane("General3", pane); 
     accordion.getPanes().add(tiledPane); 

     root.setLeft(accordion); 
     return root; 
    } 



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

class General1Bar { 

    public Pane getView() { 
     Pane p = new Pane(); 
     Button button = new Button("One"); 
     Button button1 = new Button("Two"); 
     VBox vBox = new VBox(5); 
     vBox.getChildren().addAll(button,button1); 
     p.getChildren().addAll(vBox); 
     return p; 
    } 

} 

class General2Bar { 
    public Pane getView() { 
     Pane p = new Pane(); 
     Button button = new Button("One"); 
     Button button1 = new Button("Two"); 
     VBox vBox = new VBox(5); 
     vBox.getChildren().addAll(button,button1); 
     p.getChildren().addAll(vBox); 
     return p; 
    } 

} 

class General3Bar { 
    public Pane getView() { 
     Pane p = new Pane(); 
     Button button = new Button("One"); 
     Button button1 = new Button("Two"); 
     VBox vBox = new VBox(5); 
     vBox.getChildren().addAll(button,button1); 
     p.getChildren().addAll(vBox); 
     return p; 
    } 
} 

我是新來的javafx。請檢查此代碼是否有錯誤告訴我..

0

嘗試使用javaFX Scene Builder中的Accordion控件。以下是它的XML代碼。

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"  minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> 
    <children> 
    <Accordion layoutX="14.0" layoutY="32.0"> 
    <panes> 
     <TitledPane animated="false" text="untitled 1"> 
     <content> 
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" /> 
     </content> 
     </TitledPane> 
     <TitledPane animated="false" text="untitled 2"> 
     <content> 
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" /> 
     </content> 
     </TitledPane> 
     <TitledPane animated="false" text="untitled 3"> 
     <content> 
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" /> 
     </content> 
     </TitledPane> 
    </panes> 
    </Accordion> 
</children> 
</AnchorPane>