JDK-4546077 : REGRESSION: JEditor pane focus problems with HTML components (submit)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2001-12-04
  • Updated: 2001-12-19
  • Resolved: 2001-12-19
Related Reports
Duplicate :  
Duplicate :  
Description

Name: gm110360			Date: 12/03/2001


Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)

1. Compile the two files below
2. Run JFocusDemo
3. After the HTML Page loads, type something in each of the login/pwd text
fields.
4. Mouse click on the submit button.
5. The submit is not caught.
6. Now, click the mouse inside the password text box to give it the cursor.
7. Tab twice so that the submit button now has focus (should show highlight
rectangle on button).
8. Mouse click the submit button.
9. The submit is caught (msg box displayed).

It appears that the submit will work only when:
a) the submit button has the current keyboard focus
b) the submit button is the very first control to get focus (i.e. by clicking on
it when the window first comes up)

//----JFocusDemo.java-----
import javax.swing.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.text.*;
import javax.swing.text.html.*;

public class JFocusDemo
{
    public static void main(String[] args)
    {
	JFrame appFrame = new JFrame("JEditorPane Focus Bug");
	appFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	JEditorPane j = new JEditorPane();
    	JScrollPane scroller = new JScrollPane(j);
	appFrame.getContentPane().add(scroller);

	j.setEditorKitForContentType("text/html", new ZHTMLEditorKit());
   
	j.setContentType("text/html");
	j.setEditable(false);
		
	try {
		j.setPage(new
URL("http://login.yahoo.com/config/login?.src=quote&.intl=us&.done=http://financ
e.yahoo.com"));
	}
	catch (Exception ex) {}
		  
        appFrame.pack();
	appFrame.setSize(1000,400);
	appFrame.setVisible(true);
    }

}
//-----end JFocusDemo.java-----


//-----ZHTMLEditorKit.java-----
import javax.swing.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.awt.event.*;

class ZHTMLEditorKit extends HTMLEditorKit
{
	private static ViewFactory factory = new ZHTMLFactory();
		
	public ViewFactory getViewFactory()
	{
		return factory;
	}

	public static class ZHTMLFactory extends HTMLFactory
	{
		public View create(Element e)
		{
			AttributeSet a = e.getAttributes();
			if (a.getAttribute(StyleConstants.NameAttribute) ==
HTML.Tag.INPUT)
			{
				if
("submit".equals(a.getAttribute(HTML.Attribute.TYPE)))
				{
					return new SubmitView(e);
				}
			}
			return super.create(e);
		}
	}
}
	

class SubmitView extends FormView
{
	public SubmitView(javax.swing.text.Element e)
	{
		super(e);
	}
	        
	public void actionPerformed(ActionEvent e)
	{
		JOptionPane.showMessageDialog(null, "Submit button pressed!");
	}
	    
}		

//-----end ZHTMLEditorKit.java-----

Release Regression From : 1.3.1_01a
The above release value was the last known release where this 
bug was knwon to work. Since then there has been a regression.

(Review ID: 136575) 
======================================================================

Comments
WORK AROUND Name: gm110360 Date: 12/03/2001 If the submit button has focus it will work. However, there seems to be some general focus weirdness that can make it difficult to reliably tab to the submit button. ======================================================================
11-06-2004

EVALUATION It happens because of a workaround in BasicTextUI.java The workaround was to return the focus to the ComponentView which might loose the focuse during the FlowView.FlowStrategy.layout The fix is to do not remove componentViews from the Container in FlowView.FlowStrategy.layout This bug was fixed as part of the fix for 4587627 Closing as duplicate. ###@###.### 2001-12-18
18-12-2001