MultiImageMenu
The MultiImageMenu
works just like the BigImageMenu with images as menu items. Admittedly the icons of the MultiImageMenu
are horizontally aligned, so that multiple menu items can be shown at the same time. The MultiImageMenu
also supports scrolling if not all menu items can be shown at one time. The currently selected item is drawn color-inverted. The desired amount of concurrently displayed menu items has to be given to the constructor. The available size per image will than be calculated and the according icons will be clipped of their dimensions exceeds the calculated size. For an accommodating appearance, icons of the same size are recommended.
The following source code example demonstrates the usage of the MultiImageMenu
. Like all other menus, this one also requires just a few lines of code to achieve a graphically appealing solution. Figure 5 shows the MultiImageMenu
in action. Like every other example in this tutorial, this one can also be downloaded as an archive. VoleMultiImageMenuExample.zip contains the according source code, images and a JControl/IDE project file.
Figure 5: The VoleMultiImageMenuExample
1 | import jcontrol.ui.vole.Frame; |
2 | import jcontrol.ui.vole.menu.MultiImageMenu; |
3 | |
4 | /** |
5 | * <p>This example demonstrates how to use the |
6 | * component MultiImageMenu within the GUI framework |
7 | * JControl/Vole.</p> |
8 | * |
9 | * <p>(C) DOMOLOGIC Home Automation GmbH 2003-2005</p> |
10 | */ |
11 | public class VoleMultiImageMenuExample extends Frame { |
12 | |
13 | /** |
14 | * Create and show a BigImageMenu |
15 | */ |
16 | public VoleMultiImageMenuExample() { |
17 | |
18 | // create a big BigImageMenu |
19 | MultiImageMenu menu = new MultiImageMenu(0, 10, 128, 38, 6); |
20 | |
21 | // add some menu items |
22 | menu.addMenuItem("menuimage1.jcif"); |
23 | menu.addMenuItem("menuimage2.jcif"); |
24 | menu.addMenuItem("menuimage3.jcif"); |
25 | menu.addMenuItem("menuimage4.jcif"); |
26 | menu.addMenuItem("menuimage5.jcif"); |
27 | menu.addMenuItem("menuimage6.jcif"); |
28 | menu.addMenuItem("menuimage7.jcif"); |
29 | menu.addMenuItem("menuimage8.jcif"); |
30 | menu.addMenuItem("menuimage9.jcif"); |
31 | |
32 | // show the menu |
33 | setMenu(menu); |
34 | show(); |
35 | } |
36 | |
37 | /** |
38 | * Instantiate the VoleBigImageMenuExample |
39 | */ |
40 | public static void main(String[] args) { |
41 | new VoleMultiImageMenuExample(); |
42 | } |
43 | } |
Listing 4: VoleMultiImageMenuExample.java