Как выделить слово, найденное с помощью регулярного выражения в javafx - PullRequest
0 голосов
/ 28 мая 2020

Я пытаюсь выделить слово в JavaFX, найденное Matcher, и всякий раз, когда появляется новое слово, я хочу выделить это новое. Это возможно? Вот мой код:

                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 );

                    }

                }

1 Ответ

0 голосов
/ 28 мая 2020

Я решил это с помощью RichTextFX.

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

...