popup = new JPopupMenu(); slider = new SliderMenuItem(); popup.add(slider); popup.add(new JSeparator()); JMenuItem ticks = new JCheckBoxMenuItem("Slider Tick Marks"); ticks.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { slider.setPaintTicks(!slider.getPaintTicks()); } }); JMenuItem labels = new JCheckBoxMenuItem("Slider Labels"); labels.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { slider.setPaintLabels(!slider.getPaintLabels()); } }); popup.add(ticks); popup.add(labels); popup.addPopupMenuListener(new PopupPrintListener()); addMouseListener(new MousePopupListener());
JFrame frame = new JFrame("Menu Element Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(new MenuElementExample()); frame.setSize(300, 300); frame.setVisible(true);