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.

JavaFX 8 TableView Text Alignment

I have the same problem as in JavaFX TableView text alignment, but old solution doesn’t work with JavaFX 8. With code below, the cells are painted red, but alignment is still left. “-fx-text-alignment” doesn’t work either.

main.fxml (rele…