1 14 package wingset; 15 16 import java.awt.event.ActionEvent ; 17 import java.awt.event.ActionListener ; 18 19 import org.wings.*; 20 21 25 public class PopupExample extends WingSetPane { 26 27 private SLabel selection; 28 29 private final ActionListener menuItemListener = new ActionListener () { 30 public void actionPerformed(ActionEvent e) { 31 selection.setText(((SMenuItem) e.getSource()).getText()); 32 } 33 }; 34 35 public SComponent createExample() { 36 37 SPopupMenu menu = new SPopupMenu(); 38 menu.add(createMenuItem("Cut")); 39 menu.add(createMenuItem("Copy")); 40 menu.add(createMenuItem("Paste")); 41 42 SMenu subMenu = new SMenu("Help"); 43 subMenu.add(createMenuItem("About")); 44 subMenu.add(createMenuItem("Topics")); 45 menu.add(subMenu); 46 47 SPopupMenu menu2 = new SPopupMenu(); 48 menu2.add(createMenuItem("Open")); 49 menu2.add(createMenuItem("Save")); 50 menu2.add(createMenuItem("Close")); 51 52 SLabel testLabel = new SLabel("This label has a context menu."); 53 testLabel.setComponentPopupMenu(menu); 54 SLabel testLabel2 = new SLabel("This label has the same context menu."); 55 testLabel2.setComponentPopupMenu(menu); 56 SLabel testLabel3 = new SLabel("This label has another context menu."); 57 testLabel3.setComponentPopupMenu(menu2); 58 SLabel selectionLabel = new SLabel("Selected Menu: "); 59 selection = new SLabel("none"); 60 61 SPanel all = new SPanel(); 62 all.add(testLabel); 63 all.add(testLabel2); 64 all.add(testLabel3); 65 all.add(selectionLabel); 66 all.add(selection); 67 return all; 68 } 69 70 private SMenuItem createMenuItem(String string) { 71 SMenuItem result = new SMenuItem(string); 72 result.addActionListener(menuItemListener); 73 return result; 74 } 75 } 76 | Popular Tags |