如何配置样式以突出显示整行背景。与大多数 IDE 一样 - 当前行背景颜色与其他代码背景不同。
类似这样的事情:
private static final Style CURRENT_LINE = styleContext.addStyle("currentLine", defaultStyle);
static {
StyleConstants.setBackground(CURRENT_LINE, Color.LIGHT_GRAY);
StyleConstants.setEnd(Style.LINE_END); // This method does't exist!
}
最佳答案
Like in most of IDE - current line background color is different to other code background.
实现此目的的一种方法是使用自定义Painter
。默认的 Painter 只会突出显示包含该行文本的区域。因此,自定义画家需要从行的开头/结尾突出显示背景。
当插入符从一行移动到另一行时,突出显示需要改变。
查看Line Painter包含上述功能的自定义画家类。
关于Java Swing 。使用 Style(不是 Highlighter 类)突出显示整行 JTextPane 的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48341322/