Name: dk106046 Date: 07/09/2002
java version "1.4.1-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b16)
Java HotSpot(TM) Client VM (build 1.4.1-rc-b16, mixed mode)
Steps to reproduce:
1) Compile the JEditorPaneTest.java listed below.
2) Prepare the test.html listed below
3) run "java JEditorPaneTest test.html"
4) Once the JEditorPaneTest is up, you should see a Input field and TextArea field, generated by html form.
5) Click the Input field (first one)
6) Type any character - you should notice that the focus jump to the TextArea instead of stay with TextArea <---------- PROBLEM!
-------------- Sample code: JEditorPaneTest.java -------------------
/*
* JEditorPaneTest.java
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class JEditorPaneTest extends JFrame {
Component c;
public JEditorPaneTest(String filename) {
super("JEditorPane Test");
String str = readHTMLFile(filename);
try{
JEditorPane jep = new JEditorPane("text/html", str);
jep.setEditable(false);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(new JScrollPane(jep), BorderLayout.CENTER);
}catch(Exception e){
e.printStackTrace();
}
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
System.exit(0);
}
});
setSize(400, 400);
show();
}
protected String readHTMLFile(String filename){
BufferedReader reader = null;
StringBuffer buff = new StringBuffer();
try{
reader = new BufferedReader(new FileReader(filename));
while (reader.ready()){
buff.append(reader.readLine() + "\n");
}
}catch(Exception e){
e.printStackTrace();
}finally{
if (reader != null){
try{ reader.close(); }catch(Exception e){ e.printStackTrace(); }
}
}
return buff.toString();
}
public static void main(String[] args) {
new JEditorPaneTest(args[0]);
}
}
--------------------------------------------------------------------
------------------ Sample File: test.html --------------------------
<html>
<body>
<form>
Input: <input name="text1" value="hello" size="80">
<p>
TextArea: <textarea name="text2" rows="10" cols="80">hello world</textarea>
</form>
</body>
</html>
--------------------------------------------------------------------
======================================================================