MenuLayoutTest.java
01 /*
02  *  Copyright (c) 1995-2010, The University of Sheffield. See the file
03  *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
04  *
05  *  This file is part of GATE (see http://gate.ac.uk/), and is free
06  *  software, licenced under the GNU Library General Public License,
07  *  Version 2, June 1991 (in the distribution as file licence.html,
08  *  and also available at http://gate.ac.uk/gate/licence.html).
09  *
10  *  Valentin Tablan 20 Feb 2003
11  *
12  *  $Id: MenuLayoutTest.java 12006 2009-12-01 17:24:28Z thomas_heitz $
13  */
14 
15 package gate.swing;
16 
17 import javax.swing.*;
18 
19 public class MenuLayoutTest extends JFrame {
20   public MenuLayoutTest() {
21     super("Displaying Long Menus");
22     JMenuBar menuBar = new JMenuBar();
23     this.setJMenuBar(menuBar);
24     JMenu bigMenu = new JMenu("bigMenu");
25     menuBar.add(bigMenu);
26 
27     // specify a layout manager for the menu
28     MenuLayout vflayout = new MenuLayout();
29     bigMenu.getPopupMenu().setLayout(vflayout);
30     for (int i = 1; i < 200; i++) {
31       JMenuItem bigMenuItem = new JMenuItem("bigMenu " + i);
32       //uncomment below for crazy sizes
33 //      bigMenuItem.setFont(bigMenuItem.getFont().deriveFont(
34 //          12 + (float)Math.random() * 10));
35       if(i > 100){
36         bigMenuItem.setFont(bigMenuItem.getFont().deriveFont((float)20));
37       }
38 
39       bigMenu.add(bigMenuItem);
40     }
41   }
42 
43   public static void main(String[] args) {
44     MenuLayoutTest frame = new MenuLayoutTest();
45     frame.setSize(250200);
46     frame.setLocation(200300);
47     frame.setVisible(true);
48   }
49 }