Swing/StyleConstants のバックアップの現在との差分(No.6)
#navi(contents-page-name): No such page: ST
2021-12-24 (金) 12:38:13
概要
JTextPane
にスタイル付けした文字列を挿入してログ風に表示します。
Screenshot
Advertisement
サンプルコード
解説
上記のサンプルでは、以下の手順でJTextPane
にスタイルを設定した文字列を追加しています。
-
JTextPane
からStyledDocument
を取得 - 予め設定しておいたエラー表示用の文字属性スタイルを
StyledDocument#getStyle("error")
メソッドで取得 - このスタイルと文字列と合わせて
Document#insertString(...)
メソッドで挿入
参考リンク
- Using Text Components (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)