Name: gm110360 Date: 04/24/2002 FULL PRODUCT VERSION : java version "1.4.0-rc" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91) Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode) FULL OPERATING SYSTEM VERSION : Microsoft Windows 2000 [Version 5.00.2195] A DESCRIPTION OF THE PROBLEM : Using the JEditorPane in "edit" mode for HTML documents and entering a hard-break (a <br> tag) does not move the cursor as expected. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : 1. Compile the example: javac BRHTMLEditorKit.java 2. Start the example: java BRHTMLEditorKit 3. Type some text, then hit the SHIFT-ENTER key. EXPECTED VERSUS ACTUAL BEHAVIOR : I would Expect the cursor to move to the next line just as when hitting the ENTER key. The cursor remains on the first line and a gap is added between the (hidden) BR element and the cursor. When typing another character, the cursor moves to the next line as expected. This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.awt.event.ActionEvent; import javax.swing.*; import javax.swing.text.*; import javax.swing.text.html.*; public class BRHTMLEditorKit extends HTMLEditorKit { /** * Called when the kit is being installed into the * a JEditorPane. Installs "SHIFT ENTER" as a hardbreak * @param c the JEditorPane */ public void install(JEditorPane c) { c.getInputMap().put(KeyStroke.getKeyStroke("shift ENTER"), "InsertHardBreak"); c.getActionMap().put("InsertHardBreak",insertHardBreakAction); super.install(c); } /** * Action to insert a HTML <br> into the document */ public static class InsertBRAction extends InsertHTMLTextAction { InsertBRAction() { super("InsertBR", "<br>", null, HTML.Tag.BR, null, null); } /** * Inserts the HTML into the document. * * @param ae the event */ public void actionPerformed(ActionEvent ae) { JEditorPane editor = getEditor(ae); if (editor != null) { try { HTMLDocument doc = getHTMLDocument(editor); int offset = editor.getSelectionStart(); getHTMLEditorKit(editor).insertHTML(doc, offset, "<br>",0,0,HTML.Tag.BR); } catch (Exception ex) { ex.printStackTrace(); } } } } private static final Action insertHardBreakAction = new InsertBRAction(); /** * Test example */ public static void main(String[] args) { JFrame f = new JFrame("HTML 4.x test"); f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); final JEditorPane pane = new JEditorPane(); pane.setEditable(true); pane.setContentType("text/html"); pane.setEditorKit(new BRHTMLEditorKit()); f.getContentPane().add(new JScrollPane(pane)); f.setSize(400, 300); f.setVisible(true); } } ---------- END SOURCE ---------- (Review ID: 143307) ======================================================================
|