package ibees.swing;
import java.awt.Toolkit;
import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
/**
* JEditorPane支持text/html,text/plain,text/rtf内容显示
* 此Demo主要展示了JEditor的用法和JFrame全屏的方法
* @author hhzxj2008
* */
public class JEditorPaneSample {
/**
* 在JEditor中显示HTML
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
JFrame jf = new JFrame("JEditorPane示例");
//text/html文本类型
final JEditorPane jep = new JEditorPane("http://csdn.net");
JScrollPane jsp = new JScrollPane(jep);//添加滚动支持
jep.addHyperlinkListener(new HyperlinkListener() {//添加链接点击监听者
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED){
try {
jep.setPage(e.getURL());//设置显示的URL资源
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
});
jf.add(jsp);
jf.setSize(Toolkit.getDefaultToolkit().getScreenSize().getSize());//窗口全屏
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
}