Hi Stuart, You will need to extend the component on which you have set the popup menu and listen to the rt-clk mouse event on the client side.
See the snippet below. However, there are some issues: 1. Will the menu items that you add dynamically have server side proxies? In such a case you will have to upload these and make them available when they are added to the popupmenu dynamically. The advantage of having server side proxies will be that you will be able to add event handlers on them on the server. 2. In case you plan to have only client side menuitems, then you will have to define action listener on the client and then generate an event to be processed on the server by the component that has the popupmenu. I hope this helps. Thanks and regards, Janak >-----Original Message----- >From: [EMAIL PROTECTED] >[mailto:[EMAIL PROTECTED] Behalf Of Stuart Booth >Sent: Monday, October 09, 2006 9:45 AM >To: [email protected] >Subject: [ULC-developer] Dynamically changing a component's Popup Menu > > >Setting a component's setComponentPopupMenu is straightforward >when using a >non-dynamic popupmenu, but I have a situation where I need to modify the >menu just before it is displayed. Doing this in Swing is pretty >simple, but >ULC lacks the necessary mouse messages to take complete control. >Is there a >recommended approach to solving this? > >-Stuart Booth (Abacus Research) > ---------------- import java.awt.Component; import java.awt.event.MouseEvent; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import com.ulcjava.base.application.AbstractApplication; import com.ulcjava.base.application.ULCBoxPane; import com.ulcjava.base.application.ULCFrame; import com.ulcjava.base.application.ULCLabel; import com.ulcjava.base.application.ULCMenuItem; import com.ulcjava.base.application.ULCPopupMenu; import com.ulcjava.base.client.UILabel; import com.ulcjava.base.development.DevelopmentRunner; public class DynamicPopuoMenuSnippet extends AbstractApplication { public void start() { final ULCMyLabel label = new ULCMyLabel("Label"); ULCPopupMenu pop = new ULCPopupMenu("Popup"); ULCMenuItem item1 = new ULCMenuItem("Item1"); ULCMenuItem item2 = new ULCMenuItem("Item2"); pop.add(item1); pop.add(item2); label.setComponentPopupMenu(pop); ULCBoxPane content = new ULCBoxPane(true); content.add(ULCBoxPane.BOX_EXPAND_EXPAND, label); ULCFrame frame = new ULCFrame("DynamicPopuoMenuSnippet"); frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE); frame.add(content); frame.setSize(300, 300); frame.setVisible(true); } public static void main(String[] args) { DevelopmentRunner .setApplicationClass(DynamicPopuoMenuSnippet.class); DevelopmentRunner.run(); } public static class ULCMyLabel extends ULCLabel { @Override protected String typeString() { return UIMyLabel.class.getName(); } public ULCMyLabel(String text) { super(text); } } public static class UIMyLabel extends UILabel { protected void showPopupMenu(MouseEvent event) { Component popupOwner = event.getComponent(); JPopupMenu popupMenu = ((JPopupMenu)getComponentPopupMenu().getBasicComponent()); JMenuItem item = new JMenuItem("DynamicItem"); // Add actionlistener and generate event to be sent to the server if you so wish popupMenu.add(item); popupMenu.show(popupOwner, event.getX(), event.getY()); } } } _______________________________________________ ULC-developer mailing list [email protected] http://lists.canoo.com/mailman/listinfo/ulc-developer
