私は約 10 の異なるデータソース (統計/エラー ログなど) を持つアプレットに取り組んでいます。各データソースは、単一のネットワーク接続によって更新され、オブザーバー メカニズムを介して更新を報告します。アプレットには、データの一部を表示するさまざまなビューがあります。すべてのビューは、データの一部のみに関心があり、必要な Observables で Observer として自身を登録します。
The views(extended JPanels) mostly consist of standard swing components (e.g. JLabels, JButton, ...). Some attributes of the components in the views depend on information from the underlying data model.
Example:
StatisticPanel::paintComponent(Graphics g) {
clearStatisticButton.setEnabled(stat.hasEntries());
minValueLabel.setText(stat.getMinValue());
super.paintComponent(g);
}
This logic is implemented in the paintComponent()
method of the StatisticPanel and the update()
methods just calls repaint(), because I didn't want the manipulate the components outside of the EDT.
Is this the intended way of updating swing components in a multi-threaded environment? Is it better to use a Runnable with SwingUtitlies.invokeLater()
? Are there better approaches for this problem?