ニュースを載せるクラスがありました。
package swing;
import java.awt.Color;
import java.net.URL;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import net.Logger;
import net.Util;
public class WebPanel extends JScrollPane implements Runnable {
private JTextPane editorPane;
private String link;
public WebPanel(final String link) {
this.link = link;
editorPane = new JTextPane();
editorPane.setContentType("text/html");
editorPane.setBackground(Color.DARK_GRAY);
editorPane.setEditable(false);
editorPane.setMargin(null);
editorPane.setBorder(null);
setBorder(null);
editorPane.setBackground(Color.DARK_GRAY);
editorPane.setText("<html><body><font color=\"#808080\"><br><center>Getting data</center></font></body></html>");
}
@Override
public void run() {
try {
editorPane.setPage(new URL(link));
} catch (Exception e) {
Logger.logError("setting web page failed ", e);
editorPane.setContentType("text/html");
editorPane.setText("<html><body><font color=\"#808080\"><br><center>Failed to get data<br>" + e.toString() + "</center></font></body></html>");
}
editorPane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent he) {
if (he.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
Util.openLink(he.getURL().toURI());
} catch (Exception e) {
Logger.logError("hyperlinkUpdate failed", e);
}
}
}
});
setViewportView(editorPane);
}
public String GetLink() {
return editorPane.getPage().toString();
}
public final void setLink(final String link) {
this.link = link;
}}
実行可能ですが、ページを更新すると(GUIクラスがあります)Lo
public static WebPanel scrollPane = new WebPanel(Util.newslink);
...
LoginForm.scrollPane.setLink(Util.newslink);
new Thread(LoginForm.scrollPane).start();
ページが読み込まれるまで、プログラムは機能しません(ボタンを押すことはできません)。を使用してスレッドを作成しようとしましinvokeLater()
たが、何も役に立ちませんでした。