-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0
-
generic
-
generic
Name: rk38400 Date: 11/11/98
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
class EditTest extends JFrame {
JTextPane ep = null;
public EditTest (){
ep = new JTextPane();
ep.setEditable(true);
ep.setContentType("text/html");
HTMLEditorKit kit = (HTMLEditorKit)ep.getEditorKit();
HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
ep.setDocument( doc );
try {
String text = "<html><head><title>Sample Doc</title></head> <body>Some plain text.<p><B>Some more text.</B></body></html>";
kit.read( new StringReader( text), doc, 0);
} catch ( Exception e){
e.printStackTrace();
}
getContentPane().setLayout(new BoxLayout(getContentPane(),
BoxLayout.Y_AXIS));
JPanel tp = new JPanel();
tp.setBorder(new EtchedBorder());
tp.add(ep);
getContentPane().add( tp );
// buttons
JPanel bp = new JPanel();
bp.setLayout(new FlowLayout());
bp.setBorder(new EtchedBorder());
getContentPane().add( bp );
String commands[] = {"font-bold","font-italic","font-underline",
"left-justify","center-justify","right-justify"};
Action as[] = kit.getActions();
for(int i=0; i< as.length; i++){
String s = (String)(as[i].getValue(Action.NAME));
for(int j=0; j<commands.length; j++)
if( s.compareTo(commands[j]) == 0){
JButton k = new JButton(s);
k.addActionListener( as[i]);
bp.add(k);
}
}
}
public static void main (String args[]){
EditTest ct = new EditTest();
ct.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}});
ct.setSize(500, 500);
ct.setVisible(true);
}
}
(Review ID: 41636)
======================================================================
- duplicates
-
JDK-4171509 HTMLEditorKit should support StyleConstants
-
- Resolved
-