Ramses Ramses - 4 months ago 7x
Java Question

How to set the encoding in a TableView

my TableView doesn't show the german Umlaut like ä ö ü although
my console shows me the right characters for Düsseldorf, Köln, München, etc.

Do I have to set a charset or the like in a tableView?


Here is an example

TableColumn<TextData, String> column;
TableView<TextData> table;
ObservableList<TextData> data = FXCollections.observableArrayList();

//part of main code
Task<ObservableList<TextData>> task = new Task() {

protected Object call() throws Exception {

IOFileOperations io = new IOFileOperations(fileName);
data = io.getData();

Platform.runLater(new Runnable() {

public void run() {

for(int i=0;i<colNumSize;i++) {
final int x=i;
column = new TableColumn<>("["+x+"]");
//populate the columns with data
column.setCellValueFactory(cellData -> cellData.getValue().dataProperty(x));
return null;
new Thread(task).start();

//method getData in class IOFileOperations
public ObservableList<TextData> getData() {
int numRow=results.length; //<-results a string of Array (String [][] results)
int numCol=results[0].length;
for(int i=0;i<numRow;i++) list.add(new TextData(i,numCol, results));
return list;

//class TextData
public class TextData {

public StringProperty [] dataValue;

public TextData(int row, int numCol, String loadedText [][]) {
this.dataValue = new StringProperty[numCol];
for(int i=0;i<numCol;i++) dataValue[i] = new SimpleStringProperty(loadedText[row][i]);


It looks like the problem is with how you're reading in your data in this class IOFileOperations

Without including that, we can't help isolate the exact problem in your implementation.
Below i've included an example to recreate the issue including how to correct it with the following text file:


Which should help you debug and correct your own implementation

public class City {
    private int id;
    private String name;

    public City(int id, String name){
        this.id = id;
        this.name = name;

    public int getId() {
        return id;

    public String getName() {
        return name;

Reading in the data:
Note that at this step we can provide the charset we want to use. With UTF-8 everything will display as expected, however if you switch between the commented line the umlauts won't be recognised

ObservableList<City> data = FXCollections.observableArrayList();
File file = new File("test.txt");
//Charset charset = StandardCharsets.US_ASCII;
Charset charset = StandardCharsets.UTF_8;
int currentId = 0;

try(BufferedReader reader = new BufferedReader(
        new InputStreamReader(new FileInputStream(file), charset))) {
    String line = reader.readLine();

    while (line != null) {
        data.add(new City(currentId, line));
        line = reader.readLine();

And setting up the TableView:

TableView<City> tableView = new TableView();
TableColumn idColumn = new TableColumn("Id");
        new PropertyValueFactory<>("id"));
TableColumn cityColumn = new TableColumn("City");
        new PropertyValueFactory<>("name"));

 tableView.getColumns().setAll(idColumn, cityColumn);

Difference between charsets:

enter image description here enter image description here