-1

最近、スタイル定数、スタイル付きドキュメント、およびテキスト ペインを使用しています。以下のコードで強調表示/選択したテキストの一部を編集できることを知っています

    StyledDocument doc = this.tpText.getStyledDocument();
    Style style = this.tpText.addStyle("stylish", null);
    StyleConstants.setForeground(style, color.BLACK);
    StyleConstants.setFontFamily(style, "Arial");
    doc.setCharacterAttributes(this.tpText.getSelectionStart(), this.tpText.getSelectionEnd() - this.tpText.getSelectionStart(), this.tpText.getStyle("stylish"), true);//This is the piece of code (last line) that will set all the attributes to the highlited text.

例として、ユーザーが「hello world」で「o worl」を強調表示/選択すると、「o worl」だけが黒に変更され、フォント文字は Arial になります。

さて、私の質問は次のとおりです。強調表示/選択されたテキストからフォント文字と色を取得するにはどうすればよいですか? それを個別の変数(色用とフォント文字用)に保存する方法を知りたいです。

4

1 に答える 1