You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaFX中LineNumberFactory生成行号不显示仅呈现灰色矩形的问题求助

JavaFX中LineNumberFactory生成行号不显示仅呈现灰色矩形的问题求助

各位好!我最近在做JavaFX项目时,尝试用LineNumberFactory给CodeArea添加行号,结果行号没正常显示出来,取而代之的是一个个灰色的矩形块。我本来以为是样式的问题,就在CSS文件里加了.lineno和.fold-indicator的样式设置,想调整背景和文字颜色,但试了之后完全没效果,问题还是存在。

先贴一下我写的CSS代码:

.fold-indicator{
    -fx-background-color:#292929;
}
.fold-indicator .lineno{
    -fx-fill:#4a4a4a;
}

然后是Java代码里创建CodeArea的部分:

private Node createTextAreaBox() {
    mainCodeArea = new CodeArea();
    mainCodeArea.setId("mainCodeArea");
    mainCodeArea.setParagraphGraphicFactory(LineNumberFactory.get(mainCodeArea));
    
    if(initialText){
        mainCodeArea.replaceText(textAreaText);
    }
    else{
        mainCodeArea.replaceText("");
    }
    
    // 实际会返回包含mainCodeArea的容器或mainCodeArea本身,代码未贴全
    return mainCodeArea;
}

有没有朋友遇到过类似的问题呀?能不能帮我看看是哪里出错了?是CSS选择器不对,还是LineNumberFactory的用法有什么我没注意到的细节?

备注:内容来源于stack exchange,提问作者ravengal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 07:39:29