How to make a red zig zag under word in JEditorPane

前端 未结 3 1789
有刺的猬
有刺的猬 2021-01-03 13:31

I need to make a simple spell checker in Java for an application that I am creating and I have searched around and have not found any straight and to the point answers.

3条回答
  •  没有蜡笔的小新
    2021-01-03 13:58

    I use jtstand's editor and SquiggleUnderlineHighlightPainter, which is also based on javax classes. I use it like this:

    JTextComponent editor = //... your editor component;
    SquiggleUnderlineHighlightPainter sqpainter = new SquiggleUnderlineHighlightPainter(Color.RED);
    try {
        editor.getHighlighter().addHighlight(beginPosition, endPosition, sqpainter);
    } 
    catch (BadLocationException e) {
        e.printStackTrace();
    }
    

    This should work with any javax.swing.text.JTextComponent, including JEditorPane. See addHighlighter.

提交回复
热议问题