JMenu and JSlider Coded Together
Let us code two JMenu and JSlider together to make a volume component in swing. That's dead simple. Here is a program demonstrating it.
As said in the post Creating MenuButtons in Swing this example is much related to it.
As said in the post Creating MenuButtons in Swing this example is much related to it.
js=new JSlider(): Create a new JSlider using the first constructor.
mbar=new JMenuBar(): Create a JMenuBar.
menu=new JMenu("Volume"): Create a JMenu menu with text Volume
menu.add(js): Add JSlider to the JMenu.
mbar.add(menu): Add JMenu (menu) to JMenuBar.
add(mbar): Add JMenuBar to frame. Don't set it. If you do, the menubar appears from starting to end of the frame. It spreads over. That may not be good. However, for a Volume like component it the adding looks better. If you wish to, it's your wish. You can change it. Note that, the license is about not to change & publish it on other sites, it doesn't restrict you to change and use it in your application.
You can download the entire source code(.java) file from Google Code here.
Other swing examples can be found at code.google.com/p/swing-examples/
No comments:
Post a Comment