JavaFx, How to insert ObservableMap into TableView?

I want to populate map values into tableview. I tried with observableList and its working fine. Whenever any value adds to list then table values are updates / refresh and shows new changes.

I want to do the same with map also. Whenever I adds any value to map table view needs to be refresh but it is not. I read so many articles but not able to solve this issue.

Article :

  1. Populate TableView with ObservableMap JavaFX
  2. How to display an ObservableMap via JavaFX’s TableView

My Java code.

public class MapExample {

    private static int i = 0;

    private TableView<Map.Entry<String, Person>> tableview;

    private ObservableMap<String, Person> map = FXCollections.observableHashMap();

    public void initialize() {

        System.out.println("Map Example !!");

        map.put("Vijay", new Person("Rahul", "Kakade"));

        map.addListener((MapChangeListener<String, Person>) change -> {
            if (change.wasAdded()) {
                System.out.println("If part !!");
                map.forEach((k, v) -> System.out
                        .println("Key :" + k + " Name :" + v.getFirstName() + " Last :" + v.getLastName()));
            } else if (change.wasRemoved()) {
                System.out.println("Else part !!");
                map.forEach((k, v) -> System.out
                        .println("Key :" + k + " Name :" + v.getFirstName() + " Last :" + v.getLastName()));

        TableColumn<Map.Entry<String, Person>, String> col = new TableColumn<>("Name");
                (TableColumn.CellDataFeatures<Map.Entry<String, Person>, String> p) -> new SimpleStringProperty(

        TableColumn<Map.Entry<String, Person>, String> col2 = new TableColumn<>("FirstName");
                (TableColumn.CellDataFeatures<Map.Entry<String, Person>, String> p) -> new SimpleStringProperty(

        TableColumn<Map.Entry<String, Person>, String> col3 = new TableColumn<>("LastName");
                (TableColumn.CellDataFeatures<Map.Entry<String, Person>, String> p) -> new SimpleStringProperty(



        ExecutorService service = Executors.newSingleThreadExecutor();

        service.execute(() -> {

            while (true) {
                try {
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block

                map.put("Vijay", new Person("Rahul" + i++, "Kakade" + i));




Person Model :

public class Person {
    private String firstName = null;
    private String lastName = null;
    //getter and setter

I know there is some small mistake but not able to solve it. Please tell me where I am wrong.

Thanks in advance.

Simple Tank Game in JavaFX

I’m trying to create simple tank game using javafx.But I have no idea how to create bot tank and program it to search the main player.I will be thankful for any help.Thank you in advance.

canvas.setOnKeyPressed in java

I want: When I press W, player 1 move up immediately.
Please help me.
Sorry for my bad English
Baby, life was good to me
But you just made it better
I love the way you stand by me
Through any kind of weather
I don’t wanna run away, just wa…