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