To reproduce click the "Run" button.
import com.sun.javafx.runtime.VersionInfo;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import static javafx.collections.FXCollections.*;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Orientation;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
public class Main extends Application {
private static ObservableList<String> data_first
= observableArrayList("un", "deux" , "trois");
private static ObservableList<String> data_second
= observableArrayList("un", "deux" , "trois");
private ListView<String> lv_first;
private ListView<String> lv_second;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
stage.setTitle(VersionInfo.getRuntimeVersion());
stage.setScene(createScene());
stage.show();
}
private Scene createScene() {
HBox root = new HBox();
lv_first = new ListView(data_first);
lv_first.setPrefSize(200, 200);
lv_first.setMaxSize(200, 200);
lv_first.setOrientation(Orientation.HORIZONTAL);
lv_second = new ListView(data_second);
lv_second.setPrefSize(200, 200);
lv_second.setMaxSize(200, 200);
lv_second.setOrientation(Orientation.HORIZONTAL);
Button add_remove = new Button("Run");
add_remove.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
lv_first.getItems().add(0, null);
lv_second.getItems().remove(0);
lv_second.getItems().add(0, null);
}
});
root.getChildren().addAll(add_remove, new VBox(3, lv_first, lv_second));
return new Scene(root);
}
}
import com.sun.javafx.runtime.VersionInfo;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import static javafx.collections.FXCollections.*;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Orientation;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
public class Main extends Application {
private static ObservableList<String> data_first
= observableArrayList("un", "deux" , "trois");
private static ObservableList<String> data_second
= observableArrayList("un", "deux" , "trois");
private ListView<String> lv_first;
private ListView<String> lv_second;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
stage.setTitle(VersionInfo.getRuntimeVersion());
stage.setScene(createScene());
stage.show();
}
private Scene createScene() {
HBox root = new HBox();
lv_first = new ListView(data_first);
lv_first.setPrefSize(200, 200);
lv_first.setMaxSize(200, 200);
lv_first.setOrientation(Orientation.HORIZONTAL);
lv_second = new ListView(data_second);
lv_second.setPrefSize(200, 200);
lv_second.setMaxSize(200, 200);
lv_second.setOrientation(Orientation.HORIZONTAL);
Button add_remove = new Button("Run");
add_remove.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
lv_first.getItems().add(0, null);
lv_second.getItems().remove(0);
lv_second.getItems().add(0, null);
}
});
root.getChildren().addAll(add_remove, new VBox(3, lv_first, lv_second));
return new Scene(root);
}
}