How to change the font size in ListView in JavaFX?


I tried this suggestion but style cannot be found.

Is there any other way?

Lots of thanks, cancelledout

6/25/2010 9:59:04 AM

Accepted Answer

It depends on the version of JavaFX, I will suppose it is about 1.3.
By default, ListView shows the result of toString() applied to the objects stored in its items variable.
But you can define a cellFactory function that will generate a ListCell that takes these objects and presents in a Node holding whatever you put in, for example a Text or Label, or something more complex. So, there, you can format the text the usual way.

Now, if you don't want to go to that level of detail, just use CSS:

  -fx-font: 18pt "Arial";
7/9/2010 4:08:29 PM

Another solution, direct approach:

ListView listView=new ListView();
            VirtualFlow ch=(VirtualFlow) listView.getChildrenUnmodifiable().get(0);
            Font anyfont=new Font("Tahoma",16);
            for (int i = 0; i < ch.getCellCount(); i++)
                Cell cell= ch.getCell(i);

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow