popup = new JPopupMenu(); slider = new SliderMenuItem(); popup.add(slider); popup.add(new JSeparator()); JMenuItem ticks = new JCheckBoxMenuItem("Slider Tick Marks"); JMenuItem labels = new JCheckBoxMenuItem("Slider Labels"); ticks.addActionListener(this); labels.addActionListener(this); popup.add(ticks); popup.add(labels); popup.addPopupMenuListener(this); addMouseListener(this);
if (event.getActionCommand() == "Slider Tick Marks") slider.setPaintTicks(!slider.getPaintTicks()); if (event.getActionCommand() == "Slider Labels") slider.setPaintLabels(!slider.getPaintLabels());
JFrame frame = new JFrame("Menu Element Example"); frame.addWindowListener(new BasicWindowMonitor()); frame.setContentPane(new MenuElementExample()); frame.setSize(300, 300); frame.setVisible(true);
popupCheck(e);
if (e.isPopupTrigger()) { popup.show(this, e.getX(), e.getY()); }
System.out.println("Popup menu is hidden!");
theValue = slider.getValue(); System.out.println("The value is now " + theValue);