2
私は通常のHTMLEditorKit()オブジェクトがあります。HTMLEditorKitのコンテンツをフィルタリング/検索する方法はありますか?
public class Logger {
public static ArrayList<String[]> log = new ArrayList<String[]>();
public static void update(String s) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy | HH:mm:ss");
String historyText = "<b>" + sdf.format(new Date()) + "</b>: " + s;
String[] sArray = { sdf.format(new Date()), s };
log.add(sArray);
append(historyText);
}
public static void append(String s) {
MainFrame.history.setEditorKit(MainFrame.historyKit);
MainFrame.history.setDocument(MainFrame.historyDoc);
try {
MainFrame.historyKit.insertHTML(MainFrame.historyDoc,
MainFrame.historyDoc.getLength(), s, 0, 0, null);
} catch (BadLocationException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
事は、私である:それは、このオブジェクトに応じて更新されますので、私は、「ログ」のいくつかの並べ替えとして使用
historyKit = new HTMLEditorKit();
historyDoc = new HTMLDocument();
history = new JEditorPane("text/html", "");
JScrollPane historyScrollPane = new JScrollPane(history);
historyPanel.add(historyScrollPane, "cell 0 0 1 2,grow");
history.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null,
null, null));
をコンポーネント自体をトラバースするよりも、JTextFieldに基づいてコンテンツをフィルタリングするために、データ構造を「トラバース」する方が複雑になると考えています(その場合、モデルと思われます)。テキストフィールドを「検索フィールド」として使用して、文書をフィルタリングするよく知られた方法はありますか?
JTextPaneを使用すると、HTMLタグを気にせずにテキストを検索できます。 – camickr
私は、テキストのさまざまな部分を強調表示できるようにHTMLキットを使用しています(日付は太字など)。同じフォント/色のすべての文字列は本当に恐ろしいです(おそらく、私はもっと巧みになり、ラベルでいくつかの黒い魔法を使ったり、高度にカスタマイズされたJTableを使用していたかもしれませんが)。もちろん、プラグマティズムに有利な形で美学を落とすという選択肢は常にあります。 –