//Datei: JEditorPaneEx.java
import java.awt.*;
import java.awt.Color;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.lang.reflect.InvocationTargetException;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Document;
import javax.swing.text.Element;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;
public class JEditorPaneEx2 extends JFrame implements HyperlinkListener
{
// EditorPane erzeugen
JTextPane editor;
JScrollPane scroller;
Point oldPoint;
StringBuffer s;
public void fill2()
{
Document styledoc=editor.getStyledDocument();
SimpleAttributeSet hrefAttr;
SimpleAttributeSet attrs ;
SimpleAttributeSet br=new SimpleAttributeSet();
br.addAttribute(StyleConstants.NameAttribute, HTML.Tag.BR);
StyleConstants.setForeground(br,Color.white);
StyleConstants.setFontSize(br,12);
for (int i=0;i<20;i++)
{
hrefAttr = new SimpleAttributeSet();
hrefAttr.addAttribute(HTML.Attribute.HREF, (new Integer(i)).toString());
hrefAttr.addAttribute(HTML.Attribute.ID,(new Integer(i)).toString());
attrs = new SimpleAttributeSet();
attrs.addAttribute(HTML.Tag.A, hrefAttr);
attrs.addAttribute(AttributeSet.NameAttribute, HTML.Tag.CONTENT);
StyleConstants.setFontSize(attrs,12);
StyleConstants.setForeground(attrs,Color.black);
try {
styledoc.insertString(styledoc.getLength(), "web" , attrs);
styledoc.insertString(styledoc.getLength(), "
" , br);
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//editor.setDocument(doci);
}
public JEditorPaneEx2()
{
super ("JEditorPane-Beispiel");
editor = new JTextPane();
editor.addHyperlinkListener(this);
editor.setEditable(false);
editor.setContentType("text/html charset=EUC-JP");
editor.setEditorKit(new HTMLEditorKit());
scroller=new JScrollPane(editor);
//getContentPane().setLayout(new FlowLayout());
getContentPane().add(scroller);
fill2();
setSize (300, 200);
}
public static void main (String[] args)
{
JEditorPaneEx2 editorEx = new JEditorPaneEx2();
editorEx.show();
}
public void hyperlinkUpdate(HyperlinkEvent event) {
// TODO Auto-generated method stub
}
}