High performance text component

Felipe Heidrich felipe.heidrich at oracle.com
Fri Aug 17 09:35:58 PDT 2012

Hi Andre,

Note that in FX every node has two representations, one in the scene layer, and other one in graphics layer.
In our case, for each Text node you created, a PGText will be created in the graphics layer (PG = prism graphics).

1) this options you created one Text with way too much data in it. Since, this node is visible, the PGText peer is initialized.
Every single char in your text will be shaped.

2) this options you created thousands of Text but just a  fraction of them are visible (which means just a fraction of the PGText need to initialized)
This means you are already saving some memory here.

I think the key here (for the big save) is to *not* create thousands of Text , only create what you need (what you have to display).
Try this code:
    public void start(Stage stage) throws Exception {
        ArrayList<String> lines = new ArrayList<String>();
        for (int i = 0; i < 100000; i++) {
            lines.add("This is line of text at index : " + i);
        ObservableList<String> list = FXCollections.observableList(lines);
        ListView<String> listView = new ListView<String>();
        Scene scene = new Scene(listView);
        stage.setTitle("ListView Sample");

It does not matter how many items you have in the lines arrays. The ListView will only create a few Text node to display its content.
I added a count and printout in Text node constructor (to verify that).
Basically, no performance degradation as the size of the collection grows.

I hope this helps you.

On Aug 16, 2012, at 11:48 AM, André Thieme wrote:

> which were over 600k LOC, then
> from this moment on the scrolling was perfectly f

More information about the openjfx-dev mailing list