Microsoft KB Archive/179852

= How To Enabling Hot-Tracking in an AFC UIPushButton =

Article ID: 179852

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Java Virtual Machine
 * Microsoft Software Development Kit for Java 2.02
 * Microsoft Software Development Kit for Java 3.2
 * Microsoft Software Development Kit for Java 2.01
 * Microsoft Software Development Kit for Java 2.02
 * Microsoft Software Development Kit for Java 3.0
 * Microsoft Software Development Kit for Java 3.1
 * Microsoft Software Development Kit for Application Foundation Classes 1.0

-



This article was previously published under Q179852



SUMMARY
The Microsoft Application Foundation Classes (AFC) includes the ability to enable hot-tracking by overriding the setHot method.



MORE INFORMATION
The sample code below demonstrates overriding the "setHot(boolean hot)" method, changing the color of the component inside a UIPushButton when the cursor is over the button.

Sample Code
import com.ms.ui.*; import com.ms.fx.*;

public class HotTrackDemo { public static void main(String args[]) {   UIFrame frame = new UIFrame("HotPushButton Example"); frame.setLayout(new UIGridLayout(3,0)); frame.setSize(320,200); frame.setVisible(true); HotPushButton btn1=new HotPushButton("BUTTON1"); HotPushButton btn2=new HotPushButton("BUTTON2"); btn2.setColors(FxColor.green,FxColor.lightGray); frame.add(btn1); frame.add(btn2); } }

class HotPushButton extends UIPushButton { java.awt.Color colorNorm=java.awt.Color.black; java.awt.Color colorHot=java.awt.Color.red; public HotPushButton(String value) { super(value); } public HotPushButton(IUIComponent comp) { super(comp); } public void setColors(java.awt.Color hot,java.awt.Color norm) { colorHot=hot; colorNorm=norm; setHot(isHot); } public void setHot(boolean hot) { super.setHot(hot); setForeground(hot?colorHot:colorNorm); // Change color of component invalidateAll; } }

