2015-04-04 101 views
0

enter image description here在javafx中布局我的复选框的最佳方式是什么?

我试图使用CSS和JavaFX现在为止,我认为正确的轨道,但我在哪里停留在对IM是检查boxes.I不能似乎让他们正确的布局来实现这个设计,按我希望他们的方式运作。我在两个盒子的每一个里放了4个复选框,并将它们放在同一个单元格中,以便能够放入样式表中设置的一个边框中,但是当我这样做时,只有第二列复选框可以工作。我尝试过其他选项,例如使用第二个gridpane并在那里放置复选框,然后将第二个gridpane放入我为场景设置的gridPane中,但那不会运行,所以我的问题是什么是最好的方法布局我的复选框,使它们看起来像这样,并正常工作?这是我到目前为止的内容

import javafx.scene.*; 
import javafx.stage.*; 
import javafx.geometry.*; 
import javafx.application.*; 
import javafx.scene.control.*; 
import javafx.scene.layout.*; 
import javafx.collections.*; 
import javafx.event.*; 
import javafx.scene.text.TextAlignment; 

    public class ClassRegistrationForm extends Application{ 

    Scene scene1; 

    Button createRequestButton,clearButton; 

    Label peLabel,mathLabel,electivesLabel,englishLabel,spaceLabel; 

    RadioButton english12,english11,english10,english9; 
    ToggleGroup group; 

ComboBox<String>electivesComboBox; 

CheckBox healthBox,sportsBox,liftingBox,aerobicsBox, 
archeryBox,swimmingBox,yogaBox,bowlingBox; 

    HBox buttonHbox; 
    VBox englishVbox,mathVbox,electivesVbox,peVbox1,peVbox2; 

    GridPane peClassesGridPane; 

    ListView<String> mathClassesListView; 
    ObservableList<String> mathClassesList; 


public void start(Stage primaryStage) throws Exception { 
    primaryStage.setTitle("Class Registration Application"); 
    primaryStage.setResizable(false); 
    primaryStage.sizeToScene(); 




     GridPane gridPane = new GridPane(); 
     peClassesGridPane = new GridPane(); 
     scene1 = new Scene(gridPane); 






     buttonHbox = new HBox(); 

     createRequestButton = new Button("Create Request"); 
     clearButton = new Button("Clear"); 
     buttonHbox.getChildren().addAll(createRequestButton,clearButton); 
     gridPane.setConstraints(buttonHbox,0,2); 


     peLabel = new Label("Pe"); 
     peClassesGridPane.setConstraints(peLabel,0,0); 
     healthBox = new CheckBox("Health"); 
     peClassesGridPane.setConstraints(healthBox,0,1); 
     yogaBox = new CheckBox("Yoga"); 
     peClassesGridPane.setConstraints(yogaBox,0,2); 
     sportsBox = new CheckBox("Sports"); 
     peClassesGridPane.setConstraints(sportsBox,0,3); 
     archeryBox = new CheckBox("Archery"); 
     peClassesGridPane.setConstraints(archeryBox,0,4); 

     spaceLabel = new Label(""); 
     peClassesGridPane.setConstraints(spaceLabel,1,0); 
     liftingBox = new CheckBox("Lift"); 
     peClassesGridPane.setConstraints(liftingBox,1,1); 
     swimmingBox = new CheckBox("Swim"); 
     peClassesGridPane.setConstraints(swimmingBox,1,2); 
     aerobicsBox = new CheckBox("Aero"); 
     peClassesGridPane.setConstraints(aerobicsBox,1,3); 
     bowlingBox = new CheckBox("Bowl"); 
     peClassesGridPane.setConstraints(bowlingBox,1,4); 
     peClassesGridPane.getChildren().addAll(
     peLabel,healthBox,yogaBox,sportsBox,archeryBox,spaceLabel, 
     liftingBox,swimmingBox,aerobicsBox,bowlingBox 
     ); 

     gridPane.setConstraints(peClassesGridPane,0,1); 



     mathVbox = new VBox(); 
     mathVbox.setAlignment(Pos.CENTER); 
     mathVbox.setPrefSize(150,100); 
     mathClassesListView = new ListView(); 
     mathClassesListView.setPrefSize(100,50); 
     mathClassesList = FXCollections.observableArrayList(
       "Algebra 1-2", 
       "Algebra 3-4", 
       "Geometry", 
       "Pre-Calculus", 
       "Calculus" 
     ); 
     mathClassesListView.setItems(mathClassesList); 



     mathLabel = new Label("Math Classes"); 
     mathVbox.getChildren().addAll(mathLabel,mathClassesListView); 
     gridPane.setConstraints(mathVbox,1,1); 




     englishVbox = new VBox(); 
     englishVbox.setPrefSize(200, 200); 
     englishVbox.setAlignment(Pos.CENTER); 
     group = new ToggleGroup(); 

    englishLabel = new Label("English Classes"); 
     englishVbox.getChildren().add(englishLabel); 
    english12 = new RadioButton("English12"); 
    english12.setToggleGroup(group); 
     englishVbox.getChildren().add(english12); 
    english11 = new RadioButton("English11"); 
    english11.setToggleGroup(group); 
     englishVbox.getChildren().add(english11); 
    english10 = new RadioButton("English12"); 
    english10.setToggleGroup(group); 
    englishVbox.getChildren().add(english10); 
    english9 = new RadioButton("English9"); 
     english9.setToggleGroup(group); 
    englishVbox.getChildren().add(english9); 
    gridPane.setConstraints(englishVbox,0,0); 

     electivesVbox = new VBox(); 
     electivesVbox.setAlignment(Pos.CENTER); 
    electivesLabel = new Label("Electives"); 


    ObservableList<String> data = FXCollections.observableArrayList("Java" 
      , "Web Design" 
      , "Welding" 
      , "Woods" 
      , "Art" 
      , "Band" 
      , "GameDesign" 
      , "Graphic Arts"); 
    electivesComboBox = new ComboBox<String>(); 
    electivesComboBox.setItems(data); 

      electivesVbox.getChildren().addAll(
    electivesLabel,electivesComboBox 
); 

     gridPane.setConstraints(electivesVbox,0,1); 



      gridPane.getChildren().addAll(
    englishVbox,electivesVbox,peVbox1,peVbox2,mathVbox, 
    buttonHbox,peClassesGridPane 
); 

    primaryStage.setScene(scene1); 
    primaryStage.show(); 
} 



public static void main(String[] args) { 

    launch(args); 

    } 




    } 
+0

一个GridPane是最好的方式来说明这些。 – 2015-04-05 01:22:06

+0

@James_D我试过这样做,但它没有编译.....我想不幸只是尝试一下,并发布代码 – 2015-04-05 01:33:19

+0

@James_D我试过你的解决方案,但结果....不会编译也许你可以发布一个工作示例? – 2015-04-05 02:09:12

回答

1

您不初始化peClassesGridPane。只需在行添加

peClassesGridPane = new GridPane();

你使用它之前。此外,从代码中完全删除多余的peVBox1peVBox2

相关问题