CJCoding With Joseph
15free / daySign inCreate account
Back to Multiple Choice Quiz

Select topics to narrow your question pool, then enable Random to jump to a random question matching your filters.

Topics

ComboBox Selection

Java quiz · Question 55
mediumJavaFX

What does this code do when the user selects a color from the dropdown?

Code

1ComboBox<String> colorPicker = new ComboBox<>();
2colorPicker.getItems().addAll("Red", "Green", "Blue");
3 
4Label display = new Label("No color selected");
5 
6colorPicker.setOnAction(e -> {
7 String selected = colorPicker.getValue();
8 display.setText("Color: " + selected);
9 display.setStyle("-fx-text-fill: " + selected.toLowerCase() + ";");
10});