我正在尝试突出显示Matcher找到的JavaFX中的一个单词,每当有新单词出现时,我都希望突出显示该新单词。
这可能吗?
这是我的代码:

                String s1 = displayArea.getText();
                String s2 = textInputArea.getText();
                Pattern p = Pattern.compile("[a-zA-Z]*[^\\s]");
                Matcher m1 = p.matcher(s1);
                Matcher m2 = p.matcher(s2);
                int counter=0;


                System.out.println("Words from string \"" + s1 + "\" : ");
                while (m1.find() && m2.find() ) {

                    System.out.println("Found words: "+m1.group()+ " Typed words: "+m2.group() );
                    //m1.group() needs to be highlighted and displayed in textarea
                    if (m1.group().equals(m2.group())){
                        counter++;
                        System.out.println("counter:"+counter );

                    }else if (!(m1.group().equals(m2.group())) && typedKey==' '){
                            negativni++;
                            System.out.println("negativni:"+ negativni );

                    }

                }

最佳答案

我使用RichTextFX解决了它。

displayArea.setStyle(m1.start(),m1.end(),-fx-font-weight:bold;“);

07-28 03:19
查看更多