By using
the method 'setPromptText', you can set the prompt text the the combo box.
Ex
ObservableList<String>
hobbies = FXCollections.observableArrayList("Tennis",
"Football", "Cricket", "CoCO", "Rugby",
"kabaddy");
ComboBox<String>
hobbiesComboBox = new ComboBox<>(hobbies);
hobbiesComboBox.setVisibleRowCount(3);
hobbiesComboBox.setPromptText("Select
Your Hobby");
Find the
below working application.
package com.sample.demos; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Scene; import javafx.scene.control.ComboBox; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class ComboBoxApp extends Application { @Override public void start(Stage primaryStage) throws Exception { ObservableList<String> hobbies = FXCollections.observableArrayList("Tennis", "Football", "Cricket", "CoCO", "Rugby", "kabaddy"); ComboBox<String> hobbiesComboBox = new ComboBox<>(hobbies); hobbiesComboBox.setVisibleRowCount(3); hobbiesComboBox.setPromptText("Select Your Hobby"); HBox hBox = new HBox(10, hobbiesComboBox); primaryStage.setScene(new Scene(hBox)); primaryStage.setTitle("Combo Box Example"); primaryStage.setWidth(900); primaryStage.setHeight(500); primaryStage.show(); } }
TestFX.java
package com.sample.demos; import javafx.application.Application; public class TestFX { public static void main(String args[]) { Application.launch(ComboBoxApp.class, args); } }
No comments:
Post a Comment