I am trying to handle event inside controller. How can i make "Create Profile" button work inside controller. Here are my classes:
main class
public class ApplicationLoader extends Application {
private OptionsModuleChooserRootPane view;
#Override
public void init() {
StudentProfile model = new StudentProfile();
view = new OptionsModuleChooserRootPane();
new OptionsModuleChooserController(view, model);
}
#Override
public void start(Stage stage) throws Exception {
stage.setMinWidth(530);
stage.setMinHeight(550);
stage.setTitle("Final Year Module Chooser Tool");
stage.setScene(new Scene(view));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Main View
public class OptionsModuleChooserRootPane extends BorderPane {
Menu fileMenu;
Menu helpMenu;
MenuBar menuBar;
TabPane tabPane;
List<Tab> tabs;
public CreateProfileTab profilePane;
public SelectModulesTab modulesPane;
public OverviewSelectionPane overviewPane;
public OptionsModuleChooserRootPane() {
fileMenu = new Menu("File");
helpMenu = new Menu("Help");
menuBar = new MenuBar();
tabPane = new TabPane();
tabs = new ArrayList<>();
//------------------ File menu ----------------------------
fileMenu.getItems().add(new MenuItem("Load Student Data"));
fileMenu.getItems().add(new MenuItem("Save Student Data"));
fileMenu.getItems().add(new MenuItem("Exit"));
//----------------- Help menu -----------------------------
helpMenu.getItems().add(new MenuItem("About"));
//----------------- MenuBar containing all menus ---------
menuBar.getMenus().addAll(fileMenu,helpMenu);
this.setTop(menuBar);
profilePane = new CreateProfileTab();
modulesPane = new SelectModulesTab();
overviewPane = new OverviewSelectionPane();
//-------------------------------- Tabs -----------------------------------------------------
tabs.add(addNewTab(tabPane, "Create Profile", profilePane, false));
tabs.add(addNewTab(tabPane, "Select Modules", modulesPane, false));
tabs.add(addNewTab(tabPane, "Overview Selection", overviewPane, false));
this.setCenter(tabPane);
}
private Tab addNewTab(final TabPane tabPane, String newTabName, Pane newTabContent, boolean isCloseable) {
Tab newTab = new Tab(newTabName);
newTab.setContent(newTabContent);
newTab.setClosable(isCloseable);
tabPane.getTabs().add(newTab);
return newTab;
}
}
I have created separate files for all three tabs. Here is the "Create Profile" tab class which has the button i am trying to handle event of.
public class CreateProfileTab extends GridPane {
private Label lSelectCousrse;
private ComboBox<Course> cboCourses;
private Label lPNumber;
private TextField tfPNumber;
private Label lFirstName;
private TextField tfFirstName;
private Label lSurname;
private TextField tfSurname;
private Label lEmail;
private TextField tfEmail;
private Label lDate;
private DatePicker datePicker;
private HBox hboxDate;
private Button btnCreateProfile;
private StudentProfile student = null;
private Name name;
public CreateProfileTab(){
this.setMinSize(400, 200);
this.setPadding(new Insets(10, 10, 10, 10));
this.setVgap(15);
this.setHgap(20);
this.setAlignment(Pos.CENTER);
lSelectCousrse = new Label("Select course:");
cboCourses = new ComboBox<Course>();
lPNumber = new Label("Input P number:");
tfPNumber = new TextField();
lFirstName = new Label("Input first name:");
tfFirstName = new TextField();
lSurname = new Label("Input surname");
tfSurname = new TextField();
lEmail = new Label("Input email:");
tfEmail = new TextField();
lDate = new Label("Input date:");
datePicker = new DatePicker();
hboxDate = new HBox(datePicker);
btnCreateProfile = new Button("Create Profile");
this.add(lSelectCousrse, 0, 0);
GridPane.setHalignment(lSelectCousrse, HPos.RIGHT);
this.add(cboCourses, 1, 0);
this.add(lPNumber, 0, 1);
GridPane.setHalignment(lPNumber, HPos.RIGHT);
this.add(tfPNumber, 1, 1);
this.add(lFirstName,0,2);
GridPane.setHalignment(lFirstName, HPos.RIGHT);
this.add(tfFirstName,1,2);
this.add(lSurname,0,3);
GridPane.setHalignment(lSurname, HPos.RIGHT);
this.add(tfSurname,1,3);
this.add(lEmail,0,4);
GridPane.setHalignment(lEmail, HPos.RIGHT);
this.add(tfEmail,1,4);
this.add(lDate,0,5);
GridPane.setHalignment(lDate, HPos.RIGHT);
this.add(hboxDate,1,5);
this.add(btnCreateProfile,1,6);
}
public void populateComboBoxWithCourses(Course[] courses) {
cboCourses.getItems().addAll(courses);
cboCourses.getSelectionModel().select(0);
}
public Button getButton(){
return this.btnCreateProfile;
}
}
And here is my controller
public class OptionsModuleChooserController implements EventHandler<ActionEvent> {
private OptionsModuleChooserRootPane view;
private StudentProfile model;
public OptionsModuleChooserController(OptionsModuleChooserRootPane view, StudentProfile model) {
this.model = model;
this.view = view;
this.view.profilePane.populateComboBoxWithCourses(setupAndRetrieveCourses());
}
private Course[] setupAndRetrieveCourses() {
.......
}
#Override
public void handle(ActionEvent event) {
final Object source = event.getSource();
if (source.equals(this.view.profilePane.getButton())) {
System.out.println("Button has been pressed!");
}
}
}
Related
I ask for your understanding, I am a beginner;)
I'm trying to build a simple application using JavaFX. The problem is that when I open the window the first time it goes well, but if I want to change the scene it throws an error...
Exception in thread "JavaFX Application Thread"
java.lang.IllegalArgumentException:
AnchorPane#1809546[styleClass=root]is already set as root of another
scene#
Main class
public class Main extends Application{
//private Stage primaryStage;
#Override
public void start(Stage primaryStage) {
Login login = new Login();
Scene scene = login.okno();
primaryStage.setTitle("Komunikator sieciowy JAVA");
primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.show();
}
//public Stage getPrimaryStage() {
// return this.primaryStage;
//}
public static void main(String[] args) {
launch(args);
}
}
Login
public class Login {
private GridPane grid;
private Scene scene;
private Text title;
private Label nick;
private Button wejdzBtn;
private TextField userName;
//private Alert oknoDlg;
public Login() {
grid = new GridPane();
grid.setAlignment (Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25,25,25,25));
scene = new Scene (grid, 300, 150);
utworzBtn();
utworzLogin();
utworzTekst();
utworzNick();
//oknoDialogowe();
}
//private void oknoDialogowe() {
//Alert oknoDlg = new Alert(Alert.AlertType.CONFIRMATION);
//oknoDlg.setTitle("Informacja");
//oknoDlg.setContentText("test");
// oknoDlg.setHeaderText(null);
//oknoDlg.showAndWait();
//}
private void utworzBtn() {
wejdzBtn = new Button("Zaloguj si\u0119");
HBox hbBtn = new HBox(10);
hbBtn.setAlignment (Pos.BOTTOM_RIGHT);
hbBtn.getChildren().add(wejdzBtn);
grid.add(hbBtn, 1, 2);
//wejdzBtn.setDisable(true);
wejdzBtn.setOnAction(e -> {
Messages mess = new Messages();
grid.getScene().setRoot(mess.messa());;
});
}
private void utworzLogin() {
nick = new Label("Nick:");
grid.add(nick, 0, 1);
}
private void utworzNick() {
userName = new TextField();
grid.add(userName,1,1);
// informacja w polu tekstowym
userName.setPromptText("Max 15 znak\u00f3w");
userName.setFocusTraversable(false);
//maksymalna ilość znaków
final int maxLength = 15;
userName.setOnKeyTyped(t -> {
if (userName.getText().length() > maxLength)
{
int pos = userName.getCaretPosition();
userName.setText(userName.getText(0, maxLength));
userName.positionCaret(pos);
}
});
}
private void utworzTekst() {
title = new Text ("Dzień dobry!");
title.setFont(Font.font("Calibri", FontWeight.NORMAL, 20));
grid.add(title, 0, 0, 2, 1);
}
public Scene okno() {
return scene;
}
}
and and a little another class that I'm trying to change with button from login.java
public class Messages {
private AnchorPane anchor;
private Scene scena;
//private Label nick;
private Button sendBtn;
private TextField poleDoWpisywania;
private TextArea poleDoWyswietlania, pobierzNick;
public Messages() {
anchor = new AnchorPane();
scena = new Scene(anchor, 700, 600);
pobierzNick();
poleDoWpisywania();
poleDoWyswietlania();
utworzPrzycisk();
}
private void utworzPrzycisk() {
sendBtn = new Button("Wy\u015Blij");
sendBtn.setDisable(true);
}
private void pobierzNick(){
pobierzNick = new TextArea();
pobierzNick.setEditable(false);
pobierzNick.setWrapText(true);
}
private void poleDoWpisywania() {
poleDoWpisywania = new TextField();
}
private void poleDoWyswietlania() {
poleDoWyswietlania = new TextArea();
poleDoWyswietlania.setEditable(false);
poleDoWyswietlania.setWrapText(true);
}
public Pane messa() {
return anchor;
}
}
could I ask you to show the right way to fix the bug?
JavaFX defines a scene graph which is a tree data structure that has a single root node. For your application (i.e. the code you posted), the root node is the primaryStage (this is the parameter in method start() in class Main). The primaryStage can have several Scenes. Each Scene must have its own root node.
The error message you are getting means that a Scene's root cannot also be the root of another Scene. In other words anchor is the root for scena in class Messages which means it can't be set as the root for scene in class Login.
Apart from that, if you want to change Scene's you need to call method setScene() of class Stage. Here is your Login class and Messages class with changes that solve the run-time error you are getting and perform the scene change when the user clicks on wejdzBtn button.
Login.java
(I only changed the lambda expression in method utworzBtn().)
public class Login {
private GridPane grid;
private Scene scene;
private Text title;
private Label nick;
private Button wejdzBtn;
private TextField userName;
public Login() {
grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25,25,25,25));
scene = new Scene(grid, 300, 150);
utworzBtn();
utworzLogin();
utworzTekst();
utworzNick();
}
private void utworzBtn() {
wejdzBtn = new Button("Zaloguj si\u0119");
HBox hbBtn = new HBox(10);
hbBtn.setAlignment (Pos.BOTTOM_RIGHT);
hbBtn.getChildren().add(wejdzBtn);
grid.add(hbBtn, 1, 2);
wejdzBtn.setOnAction(e -> {
Messages mess = new Messages();
Window w = scene.getWindow();
if (w instanceof Stage) {
Stage s = (Stage) w;
s.setScene(mess.getScena());
}
});
}
private void utworzLogin() {
nick = new Label("Nick:");
grid.add(nick, 0, 1);
}
private void utworzNick() {
userName = new TextField();
grid.add(userName,1,1);
userName.setPromptText("Max 15 znak\u00f3w");
userName.setFocusTraversable(false);
final int maxLength = 15;
userName.setOnKeyTyped(t -> {
if (userName.getText().length() > maxLength)
{
int pos = userName.getCaretPosition();
userName.setText(userName.getText(0, maxLength));
userName.positionCaret(pos);
}
});
}
private void utworzTekst() {
title = new Text ("Dzień dobry!");
title.setFont(Font.font("Calibri", FontWeight.NORMAL, 20));
grid.add(title, 0, 0, 2, 1);
}
public Scene okno() {
return scene;
}
}
Messages.java
(I added method getScena().)
public class Messages {
private AnchorPane anchor;
private Scene scena;
private Button sendBtn;
private TextField poleDoWpisywania;
private TextArea poleDoWyswietlania, pobierzNick;
public Messages() {
anchor = new AnchorPane();
scena = new Scene(anchor, 700, 600);
pobierzNick();
poleDoWpisywania();
poleDoWyswietlania();
utworzPrzycisk();
}
private void utworzPrzycisk() {
sendBtn = new Button("Wy\u015Blij");
sendBtn.setDisable(true);
}
private void pobierzNick() {
pobierzNick = new TextArea();
pobierzNick.setEditable(false);
pobierzNick.setWrapText(true);
}
private void poleDoWpisywania() {
poleDoWpisywania = new TextField();
}
private void poleDoWyswietlania() {
poleDoWyswietlania = new TextArea();
poleDoWyswietlania.setEditable(false);
poleDoWyswietlania.setWrapText(true);
}
public Scene getScena() {
return scena;
}
public Pane messa() {
return anchor;
}
}
Thanks a lot Abra, I've been thinking about it for the last 6 hours and haven't noticed this problem. I have also removed
public Pane messa ();
return anchor;
I do not need it ;)
I have a ComboBox<MyItem> and I want to show a DatePicker when I select a special item from the ComboBox. I created a class that extends ComboBox, and I have a DatePicker in that class. I have added a listener to its selectedItemProperty:
public class CustomComboBox extends ComboBox<MyItem>{
private DatePicker datePicker;
public CustomComboBox(){
getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if (MyItem.DATE.equals(newValue)) {
initDatePicker();
datePicker.show();
datePicker.requestFocus();
}
});
}
private void initDatePicker() {
if (datePicker == null) {
datePicker = new DatePicker();
datePicker.setFocusTraversable(false);
}
}
}
So if I select the DATE item the DatePicker should pop up and If I select a date I want to add as the value of the ComboBox
First of all why the datePicker not pops up? The second question is this posible to add the selected date to comboBox as value.
I assume you need something like this:
I did it by using a popup class from ControlsFX library.
Play with this demo app to understand the main idea.
import org.controlsfx.control.PopOver;
// here all other needed dependencies
public class Main extends Application {
private static final String DATE_TYPE = "DATE";
private class ComboBoxNode {
private Object value;
private String type;
private ComboBoxNode(final Object value, final String type) {
this.value = value;
this.type = type;
}
#Override
public String toString() {
return Objects.toString(value);
}
}
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
final ObservableList<ComboBoxNode> items =
FXCollections.observableArrayList(
new ComboBoxNode(LocalDate.now(), DATE_TYPE),
new ComboBoxNode("11:35AM", "TIME"));
final PopOver datePopOver = new PopOver();
datePopOver.setTitle("Enter new date");
datePopOver.setCornerRadius(10);
datePopOver.setHeaderAlwaysVisible(true);
datePopOver.setCloseButtonEnabled(true);
datePopOver.setAutoHide(true);
final ComboBox<ComboBoxNode> customComboBox = new ComboBox<>(items);
customComboBox.getSelectionModel().selectedItemProperty().addListener((o, old, newNode) -> {
if (newNode != null) {
if (newNode.type.equals(DATE_TYPE)) {
final DatePicker datePicker = new DatePicker((LocalDate) newNode.value);
datePicker.valueProperty().addListener((obs, oldDate, newDate) -> {
items.set(customComboBox.getSelectionModel().getSelectedIndex(), new ComboBoxNode(newDate, DATE_TYPE));
datePopOver.hide();
});
final StackPane stackPane = new StackPane(datePicker);
stackPane.setPadding(new Insets(10, 10, 10, 10));
datePopOver.setContentNode(stackPane);
datePopOver.show(customComboBox);
} else {
datePopOver.hide();
}
}
});
final FlowPane pane = new FlowPane(customComboBox);
pane.setPadding(new Insets(10, 10, 10, 10));
pane.setPrefWidth(400);
pane.setPrefHeight(300);
// Show Scene
final Scene scene = new Scene(pane);
primaryStage.setTitle("Popup calendar");
primaryStage.setScene(scene);
primaryStage.show();
}
}
How do I resize a web view correctly? The moment the window gets reduced to a smaller size it seems to push the WebView to the end of the frame, without actually resizing. How would I do this correctly allowing the window to be resized and the WebView to fit in the frame appropriately.
public class OuroborosViewer extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) {
stage.setTitle("Ouroboros");
Scene scene = new Scene(new VBox(), 1920, 1080);
scene.setFill(Color.OLDLACE);
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu("File");
Menu menuEdit = new Menu("Edit");
Menu menuView = new Menu("View");
menuBar.getMenus().addAll(menuFile, menuEdit, menuView);
((VBox) scene.getRoot()).getChildren().addAll(menuBar);
BorderPane borderPane = createTab(scene);
((VBox) scene.getRoot()).getChildren().add(borderPane);
scene.widthProperty().addListener(new WidthListener());
scene.heightProperty().addListener(new HeightListener());
// stage.getIcons().add(new Image("Ouroboros.svg"));
stage.setScene(scene);
try {
sleep(500);
} catch (InterruptedException ex) {
Logger.getLogger(OuroborosViewer.class.getName()).log(Level.SEVERE, null, ex);
}
stage.show();
}
private BorderPane createTab(Scene scene) {
TabPane tabPane = new TabPane();
BorderPane borderPane = new BorderPane();
Tab tab = new Tab();
tab.setText("Google");
//VBox hbox = new VBox(new BrowserToolbar(scene), new OuroborosBrowser(scene));
VBox vbox = new VBox();
BrowserToolbar toolbar = new BrowserToolbar(scene);
OuroborosBrowser ob = new OuroborosBrowser(scene);
VBox.setVgrow(toolbar, Priority.ALWAYS);
VBox.setVgrow(ob, Priority.ALWAYS);
vbox.getChildren().addAll(toolbar, ob);
vbox.autosize();
tabPane.getTabs().add(tab);
tab.setContent(vbox);
borderPane.setTop(tabPane);
return borderPane;
}
private static class WidthListener implements ChangeListener<Number> {
#Override
public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth, Number newSceneWidth) {
OuroborosBrowser.browsers[0].setPrefWidth(newSceneWidth.doubleValue());
BrowserToolbar.URLBars[0].setPrefWidth(newSceneWidth.doubleValue() - 115);
BrowserToolbar.toolBars[0].setPrefWidth(newSceneWidth.doubleValue());
}
}
private static class HeightListener implements ChangeListener<Number> {
#Override
public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneHeight) {
if (oldSceneHeight != newSceneHeight) {
try {
OuroborosBrowser.browsers[0].setPrefHeight(newSceneHeight.doubleValue()
+ OuroborosBrowser.browsers[0].getScene().getRoot().getChildrenUnmodifiable()
.get(0).prefHeight(0));
} catch (Exception ex) {
}
}
}
}
}
class OuroborosBrowser extends Region {
public static int browserCounter = 0;
public static WebView[] browsers = new WebView[25];
private static WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
public OuroborosBrowser(Scene scene) {
browser.setPrefSize(scene.getWidth(), scene.getHeight());
webEngine.load("http://www.google.com/index.html");
getChildren().add(browser);
browsers[browserCounter] = browser;
browserCounter++;
}
}
public class BrowserToolbar extends Region {
public static TextField[] URLBars = new TextField[25];
public static ToolBar[] toolBars = new ToolBar[25];
public static int barCounter = 0;
public BrowserToolbar(Scene scene) {
Button backButton = new Button(" < ");
Button forwardButton = new Button(" > ");
TextField URLbar = new TextField();
URLbar.setPrefWidth(scene.getWidth() - 115);
URLBars[barCounter] = URLbar;
URLbar.setPrefWidth(2000);
final ToolBar toolbar = new ToolBar(
backButton, forwardButton, URLbar);
toolbar.setPrefWidth(2000);
toolBars[barCounter] = toolbar;
barCounter++;
HBox hb = new HBox();
hb.getChildren().add(toolbar);
hb.setPrefWidth(scene.getWidth());
hb.autosize();
getChildren().add(hb);
}
}
The area shaded in the image below is the area that keeps increasing as the frame height is reduced.
link to image
I'm a really new programmer so idk if this question sounds really stupid but..
This is my main:
package culminating;
import javafx.application.Application;
& all other necessary imports...
public class CulminatingMAIN extends Application {
//Set Global variables
int count = 0;
String name;
String gender = "Boy";
Label testLabel = new Label(gender + " has been selected");
#Override
public void start(Stage primaryStage) throws Exception {
/**
* ************************ SCENE 1 WORK *************************
*/
TextField nameTextField = new TextField();
nameTextField.setMaxWidth(100);
Label nameLabel = new Label("Please enter your name.");
Label genderLabel = new Label();
Label titleLabel = new Label("Math Adventure!");
titleLabel.setFont(Font.font("Arial", FontWeight.BOLD, 30));
Rectangle titleRectangle = new Rectangle();
titleRectangle.setFill(Color.TOMATO);
titleRectangle.setWidth(280);
titleRectangle.setHeight(60);
titleRectangle.setStroke(Color.BLACK);
titleRectangle.setStrokeWidth(2.0);
StackPane root = new StackPane(titleRectangle, titleLabel);
//Set VBox properties
VBox vbox1 = new VBox(25);
vbox1.setAlignment(Pos.TOP_CENTER);
vbox1.setPadding(new Insets(60, 0, 0, 0));
vbox1.setStyle("-fx-background-color: lightskyblue");
HBox genderBtnBox = new HBox(25);
genderBtnBox.setAlignment(Pos.CENTER);
//Set Scene 1 buttons
Button enterNameBtn = new Button("Enter");
Button goToScene2Btn = new Button("Continue");
//Set Radio Button functionality here
final ToggleGroup genderGroup = new ToggleGroup();
RadioButton rb1 = new RadioButton("Boy");
rb1.setToggleGroup(genderGroup);
rb1.setUserData("Boy");
rb1.setSelected(true);
RadioButton rb2 = new RadioButton("Girl");
rb2.setToggleGroup(genderGroup);
rb2.setUserData("Girl");
//Add panes, labels and buttons to the VBox
vbox1.getChildren().addAll(root, nameLabel, nameTextField, enterNameBtn, genderLabel, genderBtnBox);
Scene scene = new Scene(vbox1, 500, 500);
primaryStage.setScene(scene);
primaryStage.setTitle("Culminating Project");
primaryStage.show();
/**
* ************************ SCENE 2 WORK *************************
*/
//THIS IS ROUGH WORK SO FAR
//Here, testing out new scene to see that it loads properly (and it does)
Circle testCircle = new Circle();
testCircle.setRadius(30);
testCircle.setFill(Color.YELLOW);
StackPane testPane = new StackPane(testCircle, testLabel);
Scene scene2 = new Scene(testPane, 500, 500);
/**
* ************************ EVENTS *************************
*/
//Stores user-entered name and prompts for user gender. Adds Continue button
enterNameBtn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
if ((count < 1) && (!nameTextField.getText().isEmpty())) {
name = nameTextField.getText();
genderLabel.setText("Hi " + name + "! Please select whether you are a boy or girl.");
genderBtnBox.getChildren().addAll(rb1, rb2);
vbox1.getChildren().add(goToScene2Btn);
count++;
}
}
});
//When pressed, changes the scene so that scene 2 is set instead
goToScene2Btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
primaryStage.setScene(scene2);
}
});
//Radio button selection is stored in gender variable
genderGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
#Override
public void changed(ObservableValue<? extends Toggle> ov,
Toggle old_toggle, Toggle new_toggle) {
if (genderGroup.getSelectedToggle() != null) {
gender = genderGroup.getSelectedToggle().getUserData().toString();
testLabel.setText(gender + " has been selected");
}
}
});
if (gender.equals("boy")){
{
}
}
else if (gender.equals("girl")){
{
}
}
}
public static void main(String[] args) {
launch(args);
}
}
Now I have another class called CharacterGraphic, which I want to call and make the graphic I created in it appear.
package culminating;
& all the other imports
public class CharacterGraphic extends Culminating_JavaFX {
public void start(Stage primaryStage) throws Exception {
String gender = "boy";
Pane pane = new Pane();
pane.setStyle("-fx-background-color: LIGHTBLUE");
pane.setPrefSize(200, 200);
Circle head = new Circle();
head.setRadius(50);
head.setCenterX(240);
head.setCenterY(120);
head.setFill(Color.BURLYWOOD);
etc etc (all other graphics i made)
How do I do this???? And where would I do this?? Any answers really, really appreciated!
I am trying to develop a wizard using the new ControlsFX 8.20.7 release. I have taken a look at the following example: BitBucket ControlsFX, and especially the method
showLinearWizard()
I simply can't understand how to use this API, can anyone help me get going or link to some examples?
This is my code right now, full of errors:
public class WizardTest extends Application {
private final ComboBox<StageStyle> styleCombobox = new ComboBox<>();
private final ComboBox<Modality> modalityCombobox = new ComboBox<>();
private final CheckBox cbUseBlocking = new CheckBox();
private final CheckBox cbCloseDialogAutomatically = new CheckBox();
private final CheckBox cbShowMasthead = new CheckBox();
private final CheckBox cbSetOwner = new CheckBox();
private final CheckBox cbCustomGraphic = new CheckBox();
private Stage stage;
#Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
showLinearWizard();
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
private void showLinearWizard() {
// define pages to show
Wizard wizard = new Wizard();
wizard.setTitle("Linear Wizard");
// --- page 1
int row = 0;
GridPane page1Grid = new GridPane();
page1Grid.setVgap(10);
page1Grid.setHgap(10);
page1Grid.add(new Label("First Name:"), 0, row);
TextField txFirstName = createTextField("firstName");
wizard.getValidationSupport().registerValidator(txFirstName, Validator.createEmptyValidator("First Name is mandatory"));
page1Grid.add(txFirstName, 1, row++);
page1Grid.add(new Label("Last Name:"), 0, row);
TextField txLastName = createTextField("lastName");
wizard.getValidationSupport().registerValidator(txLastName, Validator.createEmptyValidator("Last Name is mandatory"));
page1Grid.add(txLastName, 1, row);
WizardPane page1 = new WizardPane();
page1.setHeaderText("Please Enter Your Details");
page1.setContent(page1Grid);
// --- page 2
final WizardPane page2 = new WizardPane() {
#Override
public void onEnteringPage(Wizard wizard) {
String firstName = (String) wizard.getSettings().get("firstName");
String lastName = (String) wizard.getSettings().get("lastName");
setContentText("Welcome, " + firstName + " " + lastName + "! Let's add some newlines!\n\n\n\n\n\n\nHello World!");
}
};
page2.setHeaderText("Thanks For Your Details!");
// --- page 3
WizardPane page3 = new WizardPane();
page3.setHeaderText("Goodbye!");
page3.setContentText("Page 3, with extra 'help' button!");
ButtonType helpDialogButton = new ButtonType("Help", ButtonData.HELP_2);
page3.getButtonTypes().add(helpDialogButton);
Button helpButton = (Button) page3.lookupButton(helpDialogButton);
helpButton.addEventFilter(ActionEvent.ACTION, actionEvent -> {
actionEvent.consume(); // stop hello.dialog from closing
System.out.println("Help clicked!");
});
// create wizard
wizard.setFlow(new LinearFlow(page1, page2, page3));
System.out.println("page1: " + page1);
System.out.println("page2: " + page2);
System.out.println("page3: " + page3);
// show wizard and wait for response
wizard.showAndWait().ifPresent(result -> {
if (result == ButtonType.FINISH) {
System.out.println("Wizard finished, settings: " + wizard.getSettings());
}
});
}
private TextField createTextField(String id) {
TextField textField = new TextField();
textField.setId(id);
GridPane.setHgrow(textField, Priority.ALWAYS);
return textField;
}
}
The problem was that I forgot to add the
openjfx-dialogs.jar