Wednesday 6 June 2018

JavaFX: Set tooltip to choice box

By calling 'setTooltip' method, you can set the tool tip to choice box.

Ex
ChoiceBox<Object> choiceBox1 = new ChoiceBox<>();
choiceBox1.setTooltip(new Tooltip("Select the language"));
choiceBox1.setItems(FXCollections.observableArrayList("New", "Open File...", SEPARATOR, "close", "close all",SEPARATOR, "save", "save as", "save all"));

Find the below working application.

ChoiceBoxApp.java
package com.sample.demos;

import java.io.FileNotFoundException;
import java.net.MalformedURLException;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Separator;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class ChoiceBoxApp extends Application {
 private static final Separator SEPARATOR = new Separator();

 @Override
 public void start(Stage primaryStage) throws FileNotFoundException, MalformedURLException {
  ChoiceBox<Object> choiceBox1 = new ChoiceBox<>();
  choiceBox1.setTooltip(new Tooltip("Select the language"));
  choiceBox1.setItems(FXCollections.observableArrayList("New", "Open File...", SEPARATOR, "close", "close all",
    SEPARATOR, "save", "save as", "save all"));

  VBox vbox = new VBox(10, choiceBox1);

  Scene scene = new Scene(vbox, 400, 300);

  /* Set the scene to primaryStage, and call the show method */
  primaryStage.setTitle("JavaFX Choice Box Example");
  primaryStage.setScene(scene);
  primaryStage.show();
 }

}

TestFX.java

package com.sample.demos;

import javafx.application.Application;

public class TestFX {
 public static void main(String args[]) {
  Application.launch(ChoiceBoxApp.class, args);
 }
}





Previous                                                 Next                                                 Home

No comments:

Post a Comment