Hi Stuart, I am sending two snippets below, one in ULC and one in Swing.
Both have the same behavior under JDK 1.4 and 1.5 and Metal L&F. In JRE 1.4 - only the short desc appears in tooltip for both menu time and button. In JRE 1.5 - menu item tooltip has short desc + f9 while button tooltip has only short desc because button cannot have accelerator. So I said in my earlier mail, the tooltip is entirely detremined by L&F implementation. Kindly modify them to demo your problem. Also let me know which JRE and L&F used by you. Thanks and regards, Janak -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Friday, August 18, 2006 3:08 AM To: [EMAIL PROTECTED] Cc: [email protected] Subject: Re: [ULC-developer] Bug using Actions ? Thanks for the reply, Janak. Unfortunately, this doesn't provide me with any information that I can use to resolve this issue. Allow me to re-phrase the problem: 1) I create an action and set both the mnemonic and shortcut. 2) I create a ULCMenuItem using this action. 3) I create a ULCButton using this same action, which I add to a ULCToolBar. Now, when I run the program, I see that the menuitem is correctly showing information from the action. Alas, the tooltip that is being displayed on the toolbar's button is incorrect. The end of the tooltip shows a key combination that wasn't defined in the action. Further, this bogus shortcut key actualy works. I don't set any Look&Feel, but when I perform the exact same logic (but replacing ULC with J classes) the Swing program runs as expected. That is, the bogus key shortcut is neither displayed nor working. In conclusion, there is a difference in behavior between Swing and ULC that appears to point to a bug in ULC implementation. Can you please run this example and verify that you do see the same problem. Any help you can give that would prevent this from happening in my application would be a great help. Thanks. -Stuart Booth (Abacus Research) -----Original Message----- From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [email protected] Sent: Wed, 16 Aug 2006 9:41 AM Subject: RE: [ULC-developer] Bug using Actions ? Hi Stuart, In Swing, Accelerator can only be set on JMenuItem and not on JMenu or JButton etc. So the IAction.ACCELERATOR_KEY property of Action will be used by only those components which allow setAccelerator. ULC's behavior is that provided by Swing. The ToolTip text (i.e. whether to show acceleartor key on tooltip in addition to the message) is determined by the LookAndFeel class such as MetalToolTipUI etc. Thanks and regards, Janak ----------------------- import com.ulcjava.base.application.AbstractAction; import com.ulcjava.base.application.AbstractApplication; import com.ulcjava.base.application.ClientContext; import com.ulcjava.base.application.IAction; import com.ulcjava.base.application.ULCBoxPane; import com.ulcjava.base.application.ULCButton; import com.ulcjava.base.application.ULCFrame; import com.ulcjava.base.application.ULCMenu; import com.ulcjava.base.application.ULCMenuBar; import com.ulcjava.base.application.ULCMenuItem; import com.ulcjava.base.application.ULCToolBar; import com.ulcjava.base.application.event.ActionEvent; import com.ulcjava.base.application.util.KeyStroke; import com.ulcjava.base.development.DevelopmentRunner; public class ULCActionSnippet extends AbstractApplication { public void start() { System.out.println(ClientContext.getLookAndFeelName()); ULCToolBar toolbar = new ULCToolBar(); toolbar.add(new ULCButton(new RunAction())); ULCMenuBar menuBar = new ULCMenuBar(); ULCMenu menu = new ULCMenu("File"); ULCMenuItem menuItem = new ULCMenuItem(new RunAction()); menu.add(menuItem); menuBar.add(menu); ULCBoxPane content = new ULCBoxPane(true); content.add(toolbar); ULCFrame frame = new ULCFrame("ULCActionSnippet"); frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE); frame.add(content); frame.setMenuBar(menuBar); frame.setSize(200, 100); frame.setVisible(true); } private final class RunAction extends AbstractAction { public RunAction() { super(); putValue(IAction.NAME, "Run"); putValue(IAction.SHORT_DESCRIPTION, "Run the current project"); //putValue(IAction.MNEMONIC_KEY, new Integer('R')); putValue(IAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke("F9")); } public void actionPerformed(ActionEvent actionEvent) { System.out.println("Action Performed"); } } public static void main(String[] args) { DevelopmentRunner.setApplicationClass(ULCActionSnippet.class); DevelopmentRunner.main(args); } } ------------------------- import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JToolBar; import javax.swing.KeyStroke; import javax.swing.UIManager; import java.awt.BorderLayout; import java.awt.event.ActionEvent; public class SwingActionSnippet { public void start() { System.out.println(UIManager.getLookAndFeel().getName()); JToolBar toolbar = new JToolBar(); JButton but = new JButton(new RunAction()); toolbar.add(but); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); JMenuItem menuItem = new JMenuItem(new RunAction()); menu.add(menuItem); menuBar.add(menu); JFrame frame = new JFrame("SwingActionSnippet"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(toolbar, BorderLayout.NORTH); frame.setJMenuBar(menuBar); frame.pack(); frame.setSize(200,100); frame.setVisible(true); } private final class RunAction extends AbstractAction { public RunAction() { super(); putValue(Action.NAME, "Run"); putValue(Action.SHORT_DESCRIPTION, "Run the current project"); // putValue(Action.MNEMONIC_KEY, new Integer('R')); putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("F9")); } public void actionPerformed(ActionEvent actionEvent) { System.out.println("Action Performed " + actionEvent.getSource().getClass().getName()); } } public static void main(String[] args) { new SwingActionSnippet().start(); } } _______________________________________________ ULC-developer mailing list [email protected] http://lists.canoo.com/mailman/listinfo/ulc-developer
