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
|