Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have the same problem. It looks like a bug. Here is a full working example with a <code>ComboBox</code> that contains <code>Locale</code>s:</p> <pre><code>package org.example; import java.util.Arrays; import java.util.List; import java.util.Locale; import javafx.application.Application; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ComboBox; import javafx.scene.input.MouseEvent; import javafx.scene.layout.HBox; import javafx.stage.Stage; import javafx.util.StringConverter; public final class ComboBoxTest extends Application { @Override public void start(final Stage stage) throws Exception { // Initialize UI stage.setTitle("ComboBox Test"); final HBox root = new HBox(5.0f); final ComboBox&lt;Locale&gt; cbLocales = new ComboBox&lt;&gt;(); cbLocales.setConverter(new StringConverter&lt;Locale&gt;() { @Override public String toString(final Locale locale) { return locale.getDisplayName(); } @Override public Locale fromString(String string) { throw new UnsupportedOperationException(); } }); cbLocales.setPrefWidth(250); HBox.setMargin(cbLocales, new Insets(10)); root.getChildren().add(cbLocales); final Button btnFill = new Button("Fill"); HBox.setMargin(btnFill, new Insets(10)); root.getChildren().add(btnFill); final Scene scene = new Scene(root); stage.setScene(scene); btnFill.setOnMouseClicked(new EventHandler&lt;MouseEvent&gt;() { @Override public void handle(final MouseEvent event) { // Fill with content final List&lt;Locale&gt; locales = Arrays.asList(Locale.ENGLISH, Locale.GERMAN, Locale.FRENCH); final Locale defaultLocale = locales.get(1); // cbLocales.getItems.setAll(locales) doesn't work cbLocales.getItems().clear(); cbLocales.getItems().addAll(locales); // Set default locale cbLocales.setValue(defaultLocale); cbLocales.setPromptText(cbLocales.getConverter().toString( cbLocales.getValue())); } }); stage.show(); } public static void main(String[] args) { launch(args); } } </code></pre> <p>When the <code>ComboBox</code> filled for the first time, all works fine: The <code>ComboBox</code> contains all 3 <code>Locale</code>s and the second <code>Locale</code> is set.</p> <p><img src="https://i.stack.imgur.com/xjzuu.png" alt="enter image description here"></p> <p>After filling a second time, <code>ComboxBox.setValue</code> doesn't work: The <code>ComboBox</code> contains all 3 <code>Locale</code>s but the second <code>Locale</code> is <em>not</em> set. No item is selected an no prompt is shown.</p> <p><img src="https://i.stack.imgur.com/YThrl.png" alt="enter image description here"></p> <p>I fixed the prompt problem with</p> <pre><code>// Set default locale cbLocales.setValue(defaultLocale); cbLocales.setPromptText(cbLocales.getConverter().toString( cbLocales.getValue())); </code></pre> <p>but it doesn't select the item in the list:</p> <p><img src="https://i.stack.imgur.com/4AXPE.png" alt="enter image description here"></p> <p><strong>A work around is that:</strong></p> <pre><code>cbLocales.getSelectionModel().select(defaultLocale); cbLocales.setPromptText(cbLocales.getConverter().toString(cbLocales.getValue())); </code></pre> <p>To select the item and set the prompt. But I don't know, if there are athor problems with that (tool tips or similar)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload