JDK-5087208 : String contents of JEditorPane disappear when changing Look and Feel
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2004-08-16
  • Updated: 2004-11-09
  • Resolved: 2004-11-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6
5.0u4Fixed 6 b11Fixed
Description
Name: dk106046			Date: 08/16/2004

OPERATING SYSTEM(S):
Windows 2000 SP4

FULL JDK VERSION(S):
java version "1.5.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b57)
Java HotSpot(TM) Client VM (build 1.5.0-beta3-b57, mixed mode)

and 

java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)


1. Compile and run the sample code.

     javac JEditorPaneTest.java
     java JEditorPaneTest

  Then a JFrame opens. This frame has a text field and text area in the JEditorPane.

2. Type "aaa" in the text field at the tail of the existing text "default".

3. Type "aaa" in the text area at the tail of the existing text "default".
   
4. Change Look & Feel by selecting Look&Feel Menubar.
   Then the typed string "aaa" in the text field disappears. <---- PROBLEM!!
   On the other hand the "aaa" in the text area remains. 


---------- test.html -----------

<html>
<body>
<form>
<h4>input tag</h4>
<input name="text1" value="default" size="80">
<h4>textarea tag</h4>
<textarea name="text2" rows="10" cols="80">default</textarea>
</form>
</body>
</html>

---------- test.html -----------

---------- JEditorPaneTest.java -----------

import javax.swing.*;
import javax.swing.UIManager;
import java.awt.event.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;

public class JEditorPaneTest extends JFrame{
 private JMenuBar menubar;
 private ButtonGroup lafMenuGroup = new ButtonGroup();

 static{
  UIManager.installLookAndFeel("GTK look and feel",
     "com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
 }
 public static void main(String [] args){
  (new JEditorPaneTest()).show();
 }

 public JEditorPaneTest() {
  super("JEditorPaneTest");
  menubar = new JMenuBar();
  createUISelectMenu();
  this.setJMenuBar(menubar);
  getContentPane().setLayout(new BorderLayout());
  getContentPane().add(new JScrollPane(createJEditorPane()), BorderLayout.CENTER);
  setSize(400,500); 
 }
 
 private Component createJEditorPane(){
  File file = new File("test.html");
  JEditorPane ep = new JEditorPane();
  ep.setContentType("html/text");
  
  try {
   ep.setPage("file:" + file.getAbsolutePath());
  } catch (IOException e) {
   e.printStackTrace();
  }
  return ep;
 }

 public void createUISelectMenu() {
  JMenu menu = new JMenu("Look&Feel");
  JMenuItem item;
  LookAndFeel currentLAF=UIManager.getLookAndFeel();
  String currentLAFname=null;

  menubar.add(menu);
  if (currentLAF != null) currentLAFname=currentLAF.getName();
  UIManager.LookAndFeelInfo[] lafInfo=UIManager.getInstalledLookAndFeels();
  for (int i = 0; i < lafInfo.length; i++){
   item=createLAFMenuItem(menu,lafInfo[i].getName(),lafInfo[i].getClassName());
   if (lafInfo[i].getName().compareTo(currentLAFname) == 0) item.setSelected(true);
  }
  System.out.println("Current Look&Feel: "+ currentLAF.getClass().getName());
 }
 public JMenuItem createLAFMenuItem(JMenu menu, String label, String laf) {
  JMenuItem mi = (JRadioButtonMenuItem) menu.add(new JRadioButtonMenuItem(label));
  lafMenuGroup.add(mi);
  mi.addActionListener(new ChangeLookAndFeelAction(this, laf));
  mi.setEnabled(isAvailableLookAndFeel(laf));

  return mi;
 }
 protected boolean isAvailableLookAndFeel(String laf) {
   try {
    Class lafClass = Class.forName(laf);
    LookAndFeel newLAF = (LookAndFeel)(lafClass.newInstance());
    return newLAF.isSupportedLookAndFeel();
   } catch(Exception e) { // If ANYTHING weird happens, return false
    return false;
   }
  }

 public void setLookAndFeel(String laf) {
  try {
   UIManager.setLookAndFeel(laf);
   SwingUtilities.updateComponentTreeUI(this);
  } catch (Exception ex) {
   System.out.println("Failed loading L&F: " + laf);
   System.out.println(ex);
  }
 }
 class ChangeLookAndFeelAction extends AbstractAction {
  JEditorPaneTest app;
  String laf;
  protected ChangeLookAndFeelAction(JEditorPaneTest app, String laf) {
   this.app = app;
   this.laf = laf;
  }
  public void actionPerformed(ActionEvent e) {
   app.setLookAndFeel(laf);
   System.out.println("Current Look&Feel: "+ laf);
  }
 }

}

---------- JEditorPaneTest.java -----------

======================================================================
###@###.### 10/21/04 17:47 GMT

Comments
EVALUATION Name: sh120115 Date: 08/16/2004 This test shows a JEditorPane showing an HTML form. When the user has typed content into a text input area in that form, changing the Look and Feel causes the text to be lost. This should not happen. ###@###.### 2004-08-16 ====================================================================== will work on this bug for the next release ###@###.### 2004-08-16 Name: ap153225 Date: 08/19/2004 Text is lost because during recreation of the view sructure default values for inner HTML components like text, radio and checkboxes are restored. To manage this behaviour a special property to the HTML document can be added indicating whether the default values to the components will be set or not. ====================================================================== ###@###.### 2004-11-09 16:22:24 GMT
09-11-2004