Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8128942

[ComboBox] Dynamic element adding shifts index of currently selected element and changes it in combo box.

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: fx2.1
    • Fix Version/s: fx2.1
    • Component/s: javafx
    • Labels:
    • Environment:

      2.1b02

      Description

      See movie.

      Steps to reproduce (in common case)
      1. select some element from dropdown.
      2. using addition button, add some element BEFORE (by order, by position) selected item.
      3. note, whether selected item in ComboBox changed or not.

      Testcase:

      import com.javafx.preview.control.ComboBox;
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.Event;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ButtonBuilder;
      import javafx.scene.control.Label;
      import javafx.scene.control.TextField;
      import javafx.scene.control.TextFieldBuilder;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Pane;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class Issue1 extends Application {

          public static void main(String[] args) {
              launch(args);
          }

          final ComboBox testedComboBox = new ComboBox();

          @Override
          public void start(Stage stage) throws Exception {
              Pane pane = new Pane();
              pane.setPrefHeight(200);
              pane.setPrefWidth(200);

              pane.getChildren().add(testedComboBox);

              VBox vb = new VBox();
              vb.getChildren().addAll(pane, getAddItemHBox());
              Scene scene = new Scene(vb, 400, 400);
              stage.setScene(scene);
              stage.show();
          }

          private HBox getAddItemHBox() {
              HBox hb = new HBox();
              Label lb = new Label("Add item");
              final TextField tf = TextFieldBuilder.create().prefWidth(50).build();
              Label atLb = new Label("at pos");
              final TextField tfPos = TextFieldBuilder.create().prefWidth(50).build();
              Button bt = ButtonBuilder.create().text("Add!").build();
              bt.setOnAction(new EventHandler() {

                  public void handle(Event t) {
                      int index = Integer.parseInt(tfPos.getText());
                      ((ComboBox) testedComboBox).getItems().add(index, tf.getText());
                  }
              });
              hb.getChildren().addAll(lb, tf, atLb, tfPos, bt);
              return hb;
          }
      }

        Attachments

          Activity

            People

            • Assignee:
              jgiles Jonathan Giles
              Reporter:
              akirov Alexander Kirov (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: