Issue
I'm working on an Java app that changes components size after it's window size changes and i have a problem with ComboBox dropdown. After window size changes, first expanding of the dropdown doesnt change it's width and i get rel="nofollow noreferrer">this. When i expand the list second time, it works well, but only when i use following code:
comboBoxWindowSize.setCellFactory(new Callback<ListView<WindowSize>, ListCell<WindowSize>>() {
@Override
public ListCell<WindowSize> call(ListView<WindowSize> param) {
ListCell cell = new ListCell<WindowSize>() {
@Override
public void updateItem(WindowSize windowSize, boolean empty) {
super.updateItem(windowSize, empty);
setPrefHeight(padH25);
getListView().setPrefWidth(padW150);
if (!empty) {
setText(windowSize.toString());
} else {
setText(null);
}
}
};
return cell;
}
});
When i don't use this code, width stays incorrect all the time. I want dropdown width to be equal to ComboBox width. Will you help me fix that?
Solution
Ok, i found an answer. It's very ugly, but it actually works. Just like i said above, it's size is incorrect only in the first expanding. So all i had to do, is to expand and collapse it programmatically after i change window size:
comboBoxWindowSize.show();
comboBoxWindowSize.hide();
And thats all.
Answered By - Czachodym
Answer Checked By - Terry (JavaFixing Volunteer)