-
Bug
-
Resolution: Incomplete
-
P4
-
None
-
jfx20
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
Windows 10 Pro 21H1 / OpenJDK 19.0.2 - 20.0.2 / Gluon's Openjfx 19.0.2 - 20.0.2
A DESCRIPTION OF THE PROBLEM :
After opening the combobox and selecting an option of the dropdown list. either by clicking on it or pressing enter, the dropdown list won't dismiss until you click outside it. This happens only once, after that the combobox behaves as expected.
This behavior is oddly only present under very specific circumstances:
- The combobox has its element at index 1 selected before opening/clicking on it.
- The ObservableList used to populate the combobox gets its elements from a properties file
- The UI elements are initialized in a FXML file.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1 . Run an app with a combobox initialized with the element at index 1.
2. Click on the combobox.
3. Select any item from the dropdown list.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The dropdown list closes setting the combobox on the selected item.
ACTUAL -
The dropdown list stays open allowing to keep selecting any item until you click outside the dropdown list.
---------- BEGIN SOURCE ----------
// This example uses a few different files
// TestFX.java
package com.test.demo;
import javafx.application.Application;
public class TestFX {
public static void main(String args[]) {
Application.launch(ComboBoxApp.class, args);
}
}
// ComboBoxApp,java
package com.test.demo;
import java.util.ResourceBundle;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class ComboBoxApp extends Application{
ResourceBundle bundle = ResourceBundle.getBundle("com.test.demo.strings");
@FXML
protected ComboBox<String> itemsComboBox;
@FXML
protected HBox hBox;
private final String ITEM_ONE = bundle.getString("comboboxapp.listitem.item1");
private final String ITEM_TWO = bundle.getString("comboboxapp.listitem.item2");
private final String ITEM_THREE = bundle.getString("comboboxapp.listitem.item3");
private ObservableList<String> hobbies = FXCollections.observableArrayList();
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/com/test/demo/ComboBoxApp.fxml"));
fxmlLoader.setClassLoader(ComboBoxApp.class.getClassLoader());
fxmlLoader.setResources(bundle);
fxmlLoader.setController(this);
Parent rootNode = (Parent) fxmlLoader.load();
hobbies.add(ITEM_ONE);
hobbies.add(ITEM_TWO);
hobbies.add(ITEM_THREE);
itemsComboBox.setEditable(false);
itemsComboBox.getItems().clear();
itemsComboBox.getItems().setAll(hobbies);
itemsComboBox.getSelectionModel().select(ITEM_TWO);
primaryStage.setScene(new Scene(rootNode));
primaryStage.setTitle("Combo Box Example");
primaryStage.show();
}
}
// string.properties
# Test properties
comboboxapp.listitem.item1=Item1
comboboxapp.listitem.item2=Item2
comboboxapp.listitem.item3=Item3
// ComboBoxApp.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.collections.FXCollections?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.layout.HBox?>
<HBox fx:id="hBox" id="hBox" alignment="CENTER" xmlns:fx="http://javafx.com/fxml">
<ComboBox fx:id="itemsComboBox" id="itemsComboBox" prefHeight="30.0" prefWidth="200">
<items>
<FXCollections fx:factory="observableArrayList" />
</items>
</ComboBox>
</HBox>
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
// To avoid this issue I've added a ChangeListener to reset flag thats causing the issue, allowing the combobox
// behave as expected from the beginning.
itemsComboBox.valueProperty().addListener((observable, oldItem, newItem) -> {
itemsComboBox.show();
itemsComboBox.hide();
});
FREQUENCY : always
Windows 10 Pro 21H1 / OpenJDK 19.0.2 - 20.0.2 / Gluon's Openjfx 19.0.2 - 20.0.2
A DESCRIPTION OF THE PROBLEM :
After opening the combobox and selecting an option of the dropdown list. either by clicking on it or pressing enter, the dropdown list won't dismiss until you click outside it. This happens only once, after that the combobox behaves as expected.
This behavior is oddly only present under very specific circumstances:
- The combobox has its element at index 1 selected before opening/clicking on it.
- The ObservableList used to populate the combobox gets its elements from a properties file
- The UI elements are initialized in a FXML file.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1 . Run an app with a combobox initialized with the element at index 1.
2. Click on the combobox.
3. Select any item from the dropdown list.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The dropdown list closes setting the combobox on the selected item.
ACTUAL -
The dropdown list stays open allowing to keep selecting any item until you click outside the dropdown list.
---------- BEGIN SOURCE ----------
// This example uses a few different files
// TestFX.java
package com.test.demo;
import javafx.application.Application;
public class TestFX {
public static void main(String args[]) {
Application.launch(ComboBoxApp.class, args);
}
}
// ComboBoxApp,java
package com.test.demo;
import java.util.ResourceBundle;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class ComboBoxApp extends Application{
ResourceBundle bundle = ResourceBundle.getBundle("com.test.demo.strings");
@FXML
protected ComboBox<String> itemsComboBox;
@FXML
protected HBox hBox;
private final String ITEM_ONE = bundle.getString("comboboxapp.listitem.item1");
private final String ITEM_TWO = bundle.getString("comboboxapp.listitem.item2");
private final String ITEM_THREE = bundle.getString("comboboxapp.listitem.item3");
private ObservableList<String> hobbies = FXCollections.observableArrayList();
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/com/test/demo/ComboBoxApp.fxml"));
fxmlLoader.setClassLoader(ComboBoxApp.class.getClassLoader());
fxmlLoader.setResources(bundle);
fxmlLoader.setController(this);
Parent rootNode = (Parent) fxmlLoader.load();
hobbies.add(ITEM_ONE);
hobbies.add(ITEM_TWO);
hobbies.add(ITEM_THREE);
itemsComboBox.setEditable(false);
itemsComboBox.getItems().clear();
itemsComboBox.getItems().setAll(hobbies);
itemsComboBox.getSelectionModel().select(ITEM_TWO);
primaryStage.setScene(new Scene(rootNode));
primaryStage.setTitle("Combo Box Example");
primaryStage.show();
}
}
// string.properties
# Test properties
comboboxapp.listitem.item1=Item1
comboboxapp.listitem.item2=Item2
comboboxapp.listitem.item3=Item3
// ComboBoxApp.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.collections.FXCollections?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.layout.HBox?>
<HBox fx:id="hBox" id="hBox" alignment="CENTER" xmlns:fx="http://javafx.com/fxml">
<ComboBox fx:id="itemsComboBox" id="itemsComboBox" prefHeight="30.0" prefWidth="200">
<items>
<FXCollections fx:factory="observableArrayList" />
</items>
</ComboBox>
</HBox>
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
// To avoid this issue I've added a ChangeListener to reset flag thats causing the issue, allowing the combobox
// behave as expected from the beginning.
itemsComboBox.valueProperty().addListener((observable, oldItem, newItem) -> {
itemsComboBox.show();
itemsComboBox.hide();
});
FREQUENCY : always