我試過這個建議http://forums.sun.com/thread.jspa?threadID=5421037但找不到風格。如何更改JavaFX中ListView的字體大小?
有沒有其他辦法?
很多感謝的, cancelledout
我試過這個建議http://forums.sun.com/thread.jspa?threadID=5421037但找不到風格。如何更改JavaFX中ListView的字體大小?
有沒有其他辦法?
很多感謝的, cancelledout
這取決於JavaFX的版本,我想這大約是1.3。
默認情況下,ListView
顯示toString()
的結果應用於存儲在其變量items
中的對象。
但是你可以定義一個cellFactory
功能,將產生一個ListCell
這需要這些對象,並提出在Node
控股不管你把,例如Text
或Label
,或更復雜的東西。那麼,在那裏,您可以按照通常的方式格式化文本。現在
,如果你不想去的詳細程度,只要使用CSS:
.list-cell
{
-fx-font: 18pt "Arial";
}
另一種解決方案,直接的方法:
ListView listView=new ListView();
if(!listView.getItems().isEmpty())
{
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);
cell.setFont(anyfont);
}
}