我正在将我的聊天客户端从Swing切换到JavaFX,我遇到了图形问题.以前,我使用a JTextPane来插入样式文本,但在切换到FX时,我找不到能够做到这JTextPane一点的单个组件,从这个答案中,我知道FX TextPane也不会做这个工作.对不起,如果这对JavaFX老手来说很明显,但我似乎找不到任何东西.
如果你能推荐这样的组件,我们将不胜感激.先感谢您.
我这里有一个拼写检查器演示,从视觉上看,它正是我想要的(不正确的单词有红色下划线),但我在创建右键单击上下文菜单来应用建议时遇到问题。
我能够获得该Text对象的上下文菜单,但无法使用预测找到要替换的文本在框中的位置。
这是代码:
pom.xml
<dependency>
<groupId>org.fxmisc.richtext</groupId>
<artifactId>richtextfx</artifactId>
<version>0.10.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
<type>jar</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)
拼写检查演示.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.BreakIterator;
import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.StyleClassedTextArea;
import org.fxmisc.richtext.model.StyleSpans;
import org.fxmisc.richtext.model.StyleSpansBuilder;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.input.ContextMenuEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import org.apache.commons.text.similarity.JaroWinklerDistance;
import org.reactfx.Subscription;
public class SpellCheckingDemo extends Application
{
private static final Set<String> dictionary = new HashSet<String>(); …Run Code Online (Sandbox Code Playgroud) 我如何拼写检查用户输入TextArea的文本?
这个JavaFX组件可以实现吗?
我可以使用Java for JavaFX的标准拼写检查程序吗?