The screenshot below is a preview of JavaFX Controls. It was created in Processing4 after adding the javafx.controls module to line 1086 of JavaBuild.java and recompiling the editor. The source code and output are shown below:
Source code:
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Slider;
import javafx.scene.control.Spinner;
import javafx.scene.control.ListView;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Dialog;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Circle;
import java.time.LocalDate;
Pane pane;
Pane addControls() {
// **** Pane **** //
Pane pane = new Pane();
// **** Label **** //
Label label = new Label("Label");
Font font = Font.font("Menlo", FontWeight.BOLD, FontPosture.REGULAR, 15);
label.setFont(font);
label.setTextFill(Color.RED);
label.setTranslateX(70);
label.setTranslateY(20);
pane.getChildren().add(label);
// **** Toggle Button **** //
ToggleButton toggleBtn = new ToggleButton("Off");
toggleBtn.setLayoutX(130);
toggleBtn.setLayoutY(20);
toggleBtn.selectedProperty().addListener(((observable, oldValue, newValue) -> {
if (newValue == true) {
toggleBtn.setText("On");
} else {
toggleBtn.setText("Off");
}
}
));
pane.getChildren().add(toggleBtn);
// **** Dialog with Button **** //
Dialog<String> dialog = new Dialog<String>();
dialog.setTitle("Error Dialog");
ButtonType type = new ButtonType("Ok", ButtonData.OK_DONE);
dialog.setContentText("Message goes here.");
dialog.getDialogPane().getButtonTypes().add(type);
Button btn = new Button("Push Me");
btn.setLayoutX(350);
btn.setLayoutY(140);
btn.setOnAction(e -> {
dialog.showAndWait();
}
);
pane.getChildren().add(btn);
// **** Circle **** //
Circle circle = new Circle(400, 60, 20);
circle.setFill(Color.GREEN);
pane.getChildren().add(circle);
// **** Slider **** //
Slider slider = new Slider(1, 50, 10);
slider.setLayoutX(190);
slider.setLayoutY(20);
Tooltip tooltip1 = new Tooltip("Sets radius");
slider.setTooltip(tooltip1);
slider.valueProperty().addListener(new ChangeListener<Number>() {
public void changed(ObservableValue <?extends Number>observable, Number oldValue, Number newValue) {
circle.setRadius((double)newValue);
}
}
);
pane.getChildren().add(slider);
// **** Spinner **** //
Spinner spinner = new Spinner(0, 255, 0);
spinner.setPrefSize(70, 25);
spinner.setLayoutX(480);
spinner.setLayoutY(60);
pane.getChildren().add(spinner);
// **** ComboBox **** //
ComboBox<String> combo = new ComboBox<String>();
combo.setPromptText("Select One");
ObservableList<String> list = combo.getItems();
list.add("Java");
list.add("C++");
list.add("Python");
list.add("Processing");
combo.setLayoutX(560);
combo.setLayoutY(60);
pane.getChildren().add(combo);
// **** ListView **** //
ObservableList<String> items = FXCollections.observableArrayList("Item 1", "Item 2", "Item 3");
ListView<String> listView = new ListView<String>(items);
listView.setMaxSize(100, 80);
listView.setLayoutX(30);
listView.setLayoutY(80);
pane.getChildren().add(listView);
// **** TabPane **** //
TabPane tabPane = new TabPane();
tabPane.setLayoutX(30);
tabPane.setLayoutY(190);
Tab tab1 = new Tab("Tab 1");
Tab tab2 = new Tab("Tab 2");
Tab tab3 = new Tab("Tab 3");
tab1.setContent(new Rectangle(200, 100, Color.BLUE));
tab2.setContent(new Rectangle(200, 100, Color.RED));
tab3.setContent(new Rectangle(200, 100, Color.GREEN));
tabPane.getTabs().addAll(tab1, tab2, tab3);
pane.getChildren().add(tabPane);
// **** TextArea **** //
TextArea txtArea = new TextArea();
txtArea.setLayoutX(250);
txtArea.setLayoutY(190);
txtArea.setMaxSize(180, 130);
pane.getChildren().add(txtArea);
// **** RadioButton Group **** //
TilePane radioPane = new TilePane(15, 15);
ToggleGroup group = new ToggleGroup();
RadioButton radio1 = new RadioButton("A");
radio1.setToggleGroup(group);
radio1.setSelected(true);
RadioButton radio2 = new RadioButton("B");
radio2.setToggleGroup(group);
RadioButton radio3 = new RadioButton("C");
radio3.setToggleGroup(group);
radioPane.getChildren().addAll(radio1, radio2, radio3);
radioPane.setLayoutX(150);
radioPane.setLayoutY(100);
pane.getChildren().add(radioPane);
// **** CheckBox **** //
CheckBox cBox = new CheckBox("Checkbox");
cBox.setIndeterminate(false);
cBox.setLayoutX(60);
cBox.setLayoutY(50);
pane.getChildren().add(cBox);
// **** TextField **** //
TextField txtFld = new TextField();
txtFld.setLayoutX(150);
txtFld.setLayoutY(140);
pane.getChildren().add(txtFld);
// **** MenuBar **** //
Menu menu = new Menu("File");
MenuItem menuItem1 = new MenuItem("Open");
MenuItem menuItem2 = new MenuItem("Save");
menu.getItems().addAll(menuItem1, menuItem2);
MenuBar menuBar = new MenuBar();
menuBar.getMenus().add(menu);
pane.getChildren().add(menuBar);
// **** ToolBar **** //
ToolBar toolBar = new ToolBar();
Button openBtn = new Button("Build");
Button saveBtn = new Button("Run");
toolBar.getItems().addAll(openBtn, saveBtn);
toolBar.setLayoutX(450);
Tooltip tbarTip = new Tooltip("ToolBar");
toolBar.setTooltip(tbarTip);
pane.getChildren().add(toolBar);
// **** ProgressBar **** //
ProgressBar pBar = new ProgressBar();
pBar.setLayoutX(560);
pBar.setLayoutY(20);
pane.getChildren().add(pBar);
// **** TreeView **** //
TreeItem rootItem = new TreeItem("Pets");
TreeItem dogItem = new TreeItem("Dogs");
dogItem.getChildren().add(new TreeItem("Poodle"));
dogItem.getChildren().add(new TreeItem("Collie"));
dogItem.getChildren().add(new TreeItem("Bulldog"));
rootItem.getChildren().add(dogItem);
TreeItem catItem = new TreeItem("Cats");
catItem.getChildren().add(new TreeItem("Siamese"));
catItem.getChildren().add(new TreeItem("Ragdoll"));
catItem.getChildren().add(new TreeItem("Persian"));
rootItem.getChildren().add(catItem);
TreeView treeView = new TreeView();
treeView.setRoot(rootItem);
treeView.setLayoutX(460);
treeView.setLayoutY(110);
treeView.setMaxSize(140, 230);
//treeView.setShowRoot(false);
treeView.setShowRoot(true);
pane.getChildren().add(treeView);
// **** ColorPicker **** //
ColorPicker colorPicker = new ColorPicker();
colorPicker.setLayoutX(200);
colorPicker.setLayoutY(50);
colorPicker.setValue(Color.GREEN);
colorPicker.setOnAction(action -> {
label.setTextFill(colorPicker.getValue());
circle.setFill(colorPicker.getValue());
}
);
pane.getChildren().add(colorPicker);
// **** DatePicker **** //
DatePicker datePicker = new DatePicker();
datePicker.setLayoutX(30);
datePicker.setLayoutY(350);
datePicker.setOnAction(action -> {
LocalDate value = datePicker.getValue();
}
);
pane.getChildren().add(datePicker);
// **** Line Chart **** //
NumberAxis xAxis = new NumberAxis();
xAxis.setLabel("No. of months");
NumberAxis yAxis = new NumberAxis();
yAxis.setLabel("Dollars Per Dozen");
LineChart lineChart = new LineChart(xAxis, yAxis);
XYChart.Series dataSeries1 = new XYChart.Series();
dataSeries1.setName("2023");
dataSeries1.getData().add(new XYChart.Data( 1, 2));
dataSeries1.getData().add(new XYChart.Data( 2, 3));
dataSeries1.getData().add(new XYChart.Data(3, 4));
dataSeries1.getData().add(new XYChart.Data(4, 5));
dataSeries1.getData().add(new XYChart.Data(5, 6));
dataSeries1.getData().add(new XYChart.Data(6, 6));
lineChart.getData().add(dataSeries1);
lineChart.setTitle("Price of Eggs");
lineChart.setLayoutX(280);
lineChart.setLayoutY(350);
lineChart.setMaxSize(320, 240);
pane.getChildren().add(lineChart);
return pane;
}
void setup() {
size(1, 1, FX2D);
Stage stage = new Stage();
stage.setTitle("JavaFX Controls");
pane = addControls();
Scene scene = new Scene(pane, 700, 600);
stage.setScene(scene);
stage.show();
}
void draw() {
}
Output: