I have a ComboBox whose items are controlled by other choices in the UI. I have noticed that in Windows that when the items change have changed and you click on the ComboBox to view the popup it is often not at the correct size for the new items.
Run the provided test class in Windows:
1. Click on the ComboBox to view its popup.
2. Click on the "Change combo contents" button.
3. Click on the ComboBox again to view its popup. It appears at the same size as the first time but with a scrollbar showing. It should have resized bigger in both dimensions.
4. Select the "three three" item and notice that now the ComboBox resizes but if you click on it again the popup is still too small.
I have run the same test in Linux and the popup always seems to be the correct size. I haven't had a chance to try the same test in OS X.
****************************************** Test Class ************************************************
import java.util.ArrayList;
import java.util.List;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class ComboBoxTest extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
primaryStage.centerOnScreen();
primaryStage.setHeight(200);
primaryStage.setWidth(300);
List<String> list1 = new ArrayList<>();
list1.add("one");
list1.add("two");
list1.add("three");
List<String> list2 = new ArrayList<>();
list2.add("one");
list2.add("two");
list2.add("three three");
list2.add("four");
final ComboBox<String> combo = new ComboBox<String>();
combo.getItems().setAll(list1);
Button button = new Button("Change combo contents");
button.setOnAction(event -> {
if ( combo.getItems().size() == 3 ) {
combo.getItems().setAll(list2);
} else {
combo.getItems().setAll(list1);
}
});
VBox box = new VBox(20, combo, button );
box.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
primaryStage.setScene(new Scene( new StackPane(box) ));
primaryStage.show();
}
public static void main(String[] args) throws Exception {
launch(args);
}
}
Run the provided test class in Windows:
1. Click on the ComboBox to view its popup.
2. Click on the "Change combo contents" button.
3. Click on the ComboBox again to view its popup. It appears at the same size as the first time but with a scrollbar showing. It should have resized bigger in both dimensions.
4. Select the "three three" item and notice that now the ComboBox resizes but if you click on it again the popup is still too small.
I have run the same test in Linux and the popup always seems to be the correct size. I haven't had a chance to try the same test in OS X.
****************************************** Test Class ************************************************
import java.util.ArrayList;
import java.util.List;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class ComboBoxTest extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
primaryStage.centerOnScreen();
primaryStage.setHeight(200);
primaryStage.setWidth(300);
List<String> list1 = new ArrayList<>();
list1.add("one");
list1.add("two");
list1.add("three");
List<String> list2 = new ArrayList<>();
list2.add("one");
list2.add("two");
list2.add("three three");
list2.add("four");
final ComboBox<String> combo = new ComboBox<String>();
combo.getItems().setAll(list1);
Button button = new Button("Change combo contents");
button.setOnAction(event -> {
if ( combo.getItems().size() == 3 ) {
combo.getItems().setAll(list2);
} else {
combo.getItems().setAll(list1);
}
});
VBox box = new VBox(20, combo, button );
box.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
primaryStage.setScene(new Scene( new StackPane(box) ));
primaryStage.show();
}
public static void main(String[] args) throws Exception {
launch(args);
}
}
- relates to
-
JDK-8325564 ComboBox popup does not correctly resize after update when on display
-
- Open
-