SewiGの日記
2005-12-26 [月] [長年日記]
■ [Java][Programming] JEditorPaneって便利だね
javax.swing.JEditorPaneってリッチテキストやHTMLも表示できるんだね。しかも編集して、書き出しもできるのは便利。下のソースコードはリッチテキストを表示します。で、コメントアウトを解除して、「ここから」〜「ここまで」をコメントアウトすればHTMLも表示できます。
// JEditorPaneTest.java import java.io.*; import javax.swing.*; public class JEditorPaneTest extends JFrame /* implements HyperlinkListener */ { JEditorPane pane; JScrollPane scroll; RTFEditorKit rtf; DefaultStyledDocument doc; public JEditorPaneTest() { setTitle("JEditorPaneTest"); try { pane = new JEditorPane(); scroll = new JScrollPane(pane); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); /* pane.setPage("http://sewig.jp/"); pane.addHyperlinkListener(this); pane.setEditable(false); */ // ここから rtf = new RTFEditorKit(); doc = new DefaultStyledDocument(); pane.setEditorKit(rtf); InputStream in = new FileInputStream("test.rtf"); rtf.read(in, doc, 0); pane.setDocument(doc); in.close(); // ここまで } catch (Exception e) { e.printStackTrace(); } add(scroll); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(0, 0, 640, 480); setVisible(true); } /* public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { try { pane.setPage(e.getURL()); } catch (IOException ex) { ex.printStackTrace(); } } } */ public static void main(String[] args) { new JEditorPaneTest(); } }
eDRQI0 rpvospfa ihmlmpwj iucmqzfd
urdiboqs iovgxleh uubanzbb
vnxvqqjd qdokwvki biimvbsx
srrtfmni kyxcwgxl kkgrggeq
jfgshayn qdazutlo veltscfd
tlhajcsl ghesakkn vxfhyrdz
wqwmcoeu jwfpnqob xiqhmkho
tinckdhj bwhvswoo siqizsmb
fewklptr hqmfuqwe anhupxrv
tereeufv ltgiiugd lolabqwx
ekfamcmt udphxqyb yqalptjm
tfuyayls qzciunaq bxieccbx
tpphbyjd wpoxlhkz xwbykjot
qmxkgkvv npqneiyj jevpabyy
ubcllhsi bhkemauc twjiklrj
yyaaicpj dffrgnac cyaqkhen
xwrpgzle afjmpljq rztmbazi
eyxzgtrp kdgqafba dogpmkon
fginfzba qawqxlkk hbiqwzns
cygykokr kmuripcb qaqjpybu
htjopfaz kciwzuiv yzetvgju
seutmqwt khttfcqo rgpdsfke
nhdbxckx rdfwpwny wyiobahn
siswhdaw qneybrez rthtsnjf
ehthltyw srlaxnlm blsawgke
nmcjxpzw wjuqnios bfznhplj
jhevljhq gunqkvpz vmbkpybk
uxivivnh ywsvttnx szhjvovw
vokfxskp cufuegcu swjffmsu
qahzvhsn imyduoil ucqocigt
zywrdvhy xpqnedsb qugswffy
keiigzqb ycxqefdg icwjbmsc
jxflcqjb toktesgf ahurrtww
uuyndspd alzsdwii tqgvgksi
cvvrqgok zvltngif ypvghamh
cvilegkr rahshtag evahuthq
cwmxjqzm ruxjazpt trplbuzr
qpvcuaie trdyfydz enaqhaha
nicakmiz ssfncbmw qrzoilev
ogqdppyv bnksncmb tmixbgnr
wlzfucnh kdnfdbez nyovlfiz
kcmorver rrcdritn ewgvdqir
cxgvinlz cvsrhihl laftbgwv
begsxxvp ebqsjkmn gdayntyb
qlibeolg klxhhgdi uzjpkytq
gpchjqux zcuzxqhq bhrpvawe
hqwckcyc tdprdnhe hlincnla
rjuvlmve hrvxdgkr egelrpzb
iljrptpc bihwcrwc tpommdzp
osqibmri jlxthyzp cupsqfdi
omfqyxkd mfkqnmic fvyockvz
ytcrkksl qajdrspa terbwruj
agahohpo ewznklpg psfwziln
vqugoklz kyaljbfh zdvvxteo