Microsoft KB Archive/259961

= FIX: AFC UIPushButton May Not Fire UIActionEvent =

Article ID: 259961

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Java Virtual Machine

-



This article was previously published under Q259961



SYMPTOMS
A UIActionEvent is not generated when a user clicks on certain areas of a UIPushButton.



CAUSE
UIPushButtons contain another control that represents the actual face of the button. When the UIPushButton gets a mouse-down event, it shifts the child component over to the left and down slightly to give the visual effect of a depressed button. Because of this shift, the cursor is no longer directly over the original control, and this results in the absence of a mouse-up event. This is because both a down and an up event are required for a control to fire the UIActionEvent. See the &quot;More Information&quot; section of this article for details.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This bug has been verified to occur in both the 3100 and 3200 series of the Microsoft virtual machine.

This problem was corrected in Windows 2000 Service Pack 1.



MORE INFORMATION
An AFC button is really a special container type that holds a single child control; in most cases this is an instance of UIText and represents the face of the button. When the button is sized to its preferred size, the focus rectangle lies on the outermost edge of the UIText control.

When the button receives a mouse-down event, this child control is actually shifted down and to the left. If the user clicks on the left or top edge of the child control (x=0 or y=0), the control is no longer in the same place when the mouse up event is received. It is necessary for both the mouse-down and mouse-up events to occur over the same control in order to receive the UIActionEvent. Since the component has shifted, the mouse-up event is not fired over the same component as the mouse-down event.

Steps to Reproduce Behavior
The following applet, along with the corresponding HTML, demonstrates this problem:

Applet - afc.java

import com.ms.fx.*; import com.ms.ui.*; import com.ms.ui.event.*;

public class afc extends UIApplet implements IUIActionListener {   UIText m_txtIntro; UIPushButton m_btFocus; UIText m_txtCount; public afc {       setLayout(null); m_txtIntro = new UIText(&quot;If you click EXACTLY on the button's focus rectangle, the count won't increment.&quot;); add(m_txtIntro);

m_btFocus = new UIPushButton(&quot;Click My Focus Rectangle&quot;, UIPushButton.RAISED); m_btFocus.addActionListener(this); add(m_btFocus); m_txtCount = new UIText(&quot;0&quot;); add(m_txtCount); }   public void setBounds(int x, int y, int w, int h)    { super.setBounds(x, y, w, h); int x1 = 10; int y1 = 10; m_txtIntro.setLocation(x1, y1); m_txtIntro.setSize(m_txtIntro.getPreferredSize); x1 += m_txtIntro.getSize.width + 4; m_btFocus.setLocation(x1, y1); m_btFocus.setSize(m_btFocus.getPreferredSize); x1 += m_btFocus.getSize.width + 4; m_txtCount.setLocation(x1, y1); m_txtCount.setSize(30, 15); }   public void actionPerformed(UIActionEvent e)    { if (e.getSource == m_btFocus) {           // increment press count m_txtCount.setName(&quot;&quot; + (Integer.parseInt(m_txtCount.getName) + 1)); }   } }

class afcdlg extends UIDialog implements IUIActionListener {   UIPushButton m_btDlg = null;

public afcdlg(int nStyle) {       super(FxToolkit.getHelperUIFrame, true); }

public void actionPerformed(UIActionEvent e)   { if (e.getSource == m_btDlg) new afcdlg(1).show; } }

HTML page - AFCTest.htm   AFC Problems      

Steps to Reproduce Behavior
