vendredi 27 mars 2015

JavaFX ListView doesn't support String.format?

While using JavaFX, I've found that when I want to display a formatted string, the format doesn't work in the list itself. If I try to print it in the console, it works fine. code:



package listviewtest;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.stage.Stage;

public class FXMLDocumentController extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Listview string format test");
ListView<String> view = new ListView();
populateView(view);
primaryStage.setScene(new Scene(view, 800, 500));
primaryStage.show();
}

private void populateView(ListView view) {
String output;
ObservableList<String> outputList = FXCollections.observableArrayList();

//first outputstring
output = String.format("%-50s%-50s%-50s", "shortText", "shortText", "shortText");
System.out.println(output);
outputList.add(output);

//second outputstring
output = String.format("%-50s%-50s%-50s", "thisIsALongerTextThanBefore", "thisIsALongerTextThanBefore", "thisIsALongerTextThanBefore");
System.out.println(output);
outputList.add(output);

view.setItems(outputList);
}
}


Someone knows what's up?


Aucun commentaire:

Enregistrer un commentaire