Placing a slider in a JMenu
Hello everyone,
I am trying to place a slider in a JMenu. I have a JMenuBar set up,
and several menus on the menu bar. When the user clicks on a menu,
then on a particular item in the menu, I want a slider to show up
beside the menu bar, just like any ordinary submenu would. I know how
to do this for radio buttons using JRadioButtonMenuItem, but I don't
know if it is possible to create such a customized submenu.
I was able to make a slider show up as a submenu, but it can't be
dragged. Does anyone know how to implement this? I could make a small
slider panel pop up when the user clicks the menu item, but I'd rather
the one slider appear as a submenu item. This code does not dress up
the slider at all, but it shows how the slider is frozen and can't be
adjusted:
import java.awt.*;
import javax.swing.*;
public class SliderInMenuTester extends JFrame {
public SliderInMenuTester() {
super("Slider In Menu Test");
setSize(500, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Sample Menu");
JMenu sliderItem = new JMenu("Sample Slider");
JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 25, 10);
sliderItem.add(slider);
menu.add(sliderItem);
menuBar.add(menu);
setJMenuBar(menuBar);
setVisible(true);
}
public static void main(String[] arguments) {
SliderInMenuTester sliderInMenuTester = new SliderInMenuTester();
}
}