samedi 4 avril 2015

what is the best way to layout my checkboxes in javafx?

enter image description here


I am trying to achieve this design using css and javafx and so far i think im on the right track, but where i am stuck at is the check boxes.I cant seem to get them to layout correctly and functioning the way i want them to. I put 4 check Boxes in each of the two vboxs and put them both in the same cell to be able fit in one border that i set in the style sheet,but when i do this only the second column of check boxes work so my question is what is the best way to layout my check boxes so they look like this and are functioning properly? Here is what i have so far.



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;

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();
gridPane.getColumnConstraints().add(new ColumnConstraints(200));
gridPane.getColumnConstraints().add(new ColumnConstraints(200));

scene1 = new Scene(gridPane);




scene1.getStylesheets().add("resources/css/styleSheet.css");

buttonHbox = new HBox();

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

peVbox1 = new VBox();
peVbox1.setPrefSize(100,100);
peVbox1.setAlignment(Pos.CENTER_LEFT);
peVbox1.fillWidthProperty();
peVbox1.setId("peVbox1");
peLabel = new Label("Pe");
healthBox = new CheckBox("Health");
healthBox.setTextAlignment(TextAlignment.LEFT);
yogaBox = new CheckBox("Yoga");
sportsBox = new CheckBox("Sports");
archeryBox = new CheckBox("Archery");
peVbox1.getChildren().addAll(
peLabel,healthBox,yogaBox,sportsBox,archeryBox
);

peVbox1.getStyleClass().add("vbox");

peVbox2 = new VBox();
peVbox2.setAlignment(Pos.CENTER_RIGHT);
peVbox2.fillWidthProperty();
peVbox2.setPrefSize(100,100);
peVbox2.setId("peVbox2");
spaceLabel = new Label("");
liftingBox = new CheckBox("Lift");
swimmingBox = new CheckBox("Swim");
aerobicsBox = new CheckBox("Aero");
bowlingBox = new CheckBox("Bowl");
peVbox2.getChildren().addAll(
spaceLabel,liftingBox,swimmingBox,aerobicsBox,bowlingBox
);
gridPane.setConstraints(peVbox2,1,0);
peVbox2.getStyleClass().addAll("vbox");
gridPane.setConstraints(peVbox1,1,0);


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
);

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



public static void main(String[] args) {

launch(args);

}




}

Aucun commentaire:

Enregistrer un commentaire