Example usage for javax.swing JMenu JMenu

List of usage examples for javax.swing JMenu JMenu

Introduction

In this page you can find the example usage for javax.swing JMenu JMenu.

Prototype

public JMenu(Action a) 

Source Link

Document

Constructs a menu whose properties are taken from the Action supplied.

Usage

From source file:InternalFrameDemo.java

protected JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();

    // Set up the lone menu.
    JMenu menu = new JMenu("Document");
    menu.setMnemonic(KeyEvent.VK_D);
    menuBar.add(menu);/*w w w .j a  v  a2  s.  co m*/

    // Set up the first menu item.
    JMenuItem menuItem = new JMenuItem("New");
    menuItem.setMnemonic(KeyEvent.VK_N);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK));
    menuItem.setActionCommand("new");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    // Set up the second menu item.
    menuItem = new JMenuItem("Quit");
    menuItem.setMnemonic(KeyEvent.VK_Q);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK));
    menuItem.setActionCommand("quit");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    return menuBar;
}

From source file:uk.co.petertribble.jkstat.demo.JLoadChart.java

/**
 * A standalone demo charting load averages.
 *///from  w w w.  ja  v  a  2  s.  c o  m
public JLoadChart() {
    super("JLoadChart");

    jkstat = new NativeJKstat();
    int maxage = 600000;

    String lavetext = KstatResources.getString("LOAD.AVERAGE.TEXT");
    ts1 = new TimeSeries("1min " + lavetext);
    ts1.setMaximumItemAge(maxage);
    ts5 = new TimeSeries("5min " + lavetext);
    ts5.setMaximumItemAge(maxage);
    ts15 = new TimeSeries("15min " + lavetext);
    ts15.setMaximumItemAge(maxage);

    updateAccessory();
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(ts1);
    dataset.addSeries(ts5);
    dataset.addSeries(ts15);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(lavetext, KstatResources.getString("CHART.TIME"),
            KstatResources.getString("LOAD.LOAD.TEXT"), dataset, true, true, false);

    XYPlot xyplot = chart.getXYPlot();

    NumberAxis loadaxis = new NumberAxis(KstatResources.getString("LOAD.LOAD.TEXT"));
    loadaxis.setAutoRange(true);
    loadaxis.setAutoRangeIncludesZero(true);
    xyplot.setRangeAxis(loadaxis);

    DateAxis daxis = new DateAxis(KstatResources.getString("CHART.TIME"));
    daxis.setAutoRange(true);
    daxis.setFixedAutoRange(maxage);
    xyplot.setDomainAxis(daxis);

    addWindowListener(new winExit());
    setContentPane(new ChartPanel(chart));

    JMenuBar jm = new JMenuBar();
    JMenu jme = new JMenu(KstatResources.getString("FILE.TEXT"));
    jme.setMnemonic(KeyEvent.VK_F);
    exitItem = new JMenuItem(KstatResources.getString("FILE.EXIT.TEXT"), KeyEvent.VK_X);
    exitItem.addActionListener(this);
    jme.add(exitItem);
    jm.add(jme);

    setJMenuBar(jm);

    pack();
    setVisible(true);
    Timer timer = new Timer(5000, this);
    timer.start();
}

From source file:gdt.jgui.tool.JTextEditor.java

/**
 * Get context menu.//w w w . ja va2 s  . com
 * @return the context menu. 
 */
@Override
public JMenu getContextMenu() {
    JMenu menu = new JMenu("Context");
    JMenuItem doneItem = new JMenuItem("Done");
    doneItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //System.out.println("TextEditor:done:text="+editorPane.getText());
            if (requesterResponseLocator$ != null) {
                try {
                    byte[] ba = Base64.decodeBase64(requesterResponseLocator$);
                    String responseLocator$ = new String(ba, "UTF-8");
                    text$ = editorPane.getText();
                    if (base64)
                        text$ = Locator.compressText(text$);
                    responseLocator$ = Locator.append(responseLocator$, TEXT, text$);
                    System.out.println("TextEditor:done:response locator="
                            + Locator.remove(responseLocator$, Locator.LOCATOR_ICON));
                    JConsoleHandler.execute(console, responseLocator$);
                } catch (Exception ee) {
                    LOGGER.severe(ee.toString());
                }
            } else {
                //System.out.println("TextEditor:done:requester locator is null");
                console.back();
            }
        }
    });
    menu.add(doneItem);
    JMenuItem cancelItem = new JMenuItem("Cancel");
    cancelItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            console.back();
        }
    });
    menu.add(cancelItem);
    menu.addSeparator();
    JMenuItem encryptItem = new JMenuItem("Encrypt/Decrypt");
    encryptItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JTextEncrypter ten = new JTextEncrypter();
            String tenLocator$ = ten.getLocator();
            tenLocator$ = Locator.append(tenLocator$, Entigrator.ENTIHOME, entihome$);
            tenLocator$ = Locator.append(tenLocator$, JTextEditor.TEXT, editorPane.getText());
            String tedLocator$ = getLocator();
            tedLocator$ = Locator.append(tedLocator$, BaseHandler.HANDLER_METHOD, "response");
            tedLocator$ = Locator.append(tedLocator$, JRequester.REQUESTER_ACTION, ACTION_ENCODE_TEXT);
            tenLocator$ = Locator.append(tenLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR,
                    Locator.compressText(tedLocator$));
            JConsoleHandler.execute(console, tenLocator$);
        }
    });
    menu.add(encryptItem);
    return menu;
}

From source file:net.brtly.monkeyboard.gui.MasterControlPanel.java

public MasterControlPanel(JFrame frame) {
    _frame = frame;//  w  w w . j  a  va2 s .c o  m
    initWindowListener(frame);

    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);

    JMenu mnActions = new JMenu("Actions");
    menuBar.add(mnActions);

    JMenu mnDebug = new JMenu("Debug");
    mnActions.add(mnDebug);

    JMenuItem mntmAddPluginpanel = new JMenuItem("Request null PluginPanel");
    mntmAddPluginpanel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.out.println("Requesting null PluginPanel");
            // TODO
        }
    });
    mnDebug.add(mntmAddPluginpanel);

    JMenu mnOptions = new JMenu("Options");
    menuBar.add(mnOptions);

    _viewMenu = new JMenu("Views");

    _viewMenu.addMenuListener(new MenuListener() {

        @Override
        public void menuCanceled(MenuEvent arg0) {
        }

        @Override
        public void menuDeselected(MenuEvent arg0) {
        }

        @Override
        public void menuSelected(MenuEvent arg0) {
            updateViewMenu();
        }

    });
    menuBar.add(_viewMenu);

    // INITIALIZE MANAGERS
    // TODO: maybe call this in the Runnable and fire an event when finished
    _eventBus = new SwingEventBus();
    _eventBus.register(this);
    DeviceManager.init(_eventBus);

    _pluginManager = new PluginManager(_eventBus);
    _pluginManager.loadPlugins();

    // create the status bar panel and shove it down the bottom of the frame
    statusPanel = new StatusBar(frame);
    _frame.getContentPane().add(statusPanel, BorderLayout.SOUTH);

    _dockController = new CControl(frame);
    _frame.getContentPane().add(_dockController.getContentArea(), BorderLayout.CENTER);
    _panelFactory = new PluginPanelDockableFactory(_pluginManager);
    _dockController.addMultipleDockableFactory(PluginPanelDockableFactory.ID, _panelFactory);
    _dockController.createWorkingArea("root");

    updateViewMenu();

    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            DeviceManager.start(null);
        }
    });

    _runOnClose.add(new Runnable() {
        public void run() {
            _dockController.destroy();
            DeviceManager.stop();
            DeviceManager.shutdown();
            System.exit(0);
        }
    });
}

From source file:com.loy.MainFrame.java

@SuppressWarnings("rawtypes")
public void init() {

    String src = "ee.png";
    try {// ww w  . ja v a 2  s. c om
        ClassPathResource classPathResource = new ClassPathResource(src);
        image = ImageIO.read(classPathResource.getURL());
        this.setIconImage(image);
    } catch (IOException e) {
    }

    menu = new JMenu("LOG CONSOLE");
    this.jmenuBar = new JMenuBar();
    this.jmenuBar.add(menu);

    panel = new JPanel(new BorderLayout());
    this.add(panel);

    ClassPathResource classPathResource = new ClassPathResource("application.yml");
    Yaml yaml = new Yaml();
    Map result = null;
    try {
        result = (Map) yaml.load(classPathResource.getInputStream());
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    String platformStr = result.get("platform").toString();
    String version = result.get("version").toString();
    String jvmOption = result.get("jvmOption").toString();
    @SuppressWarnings("unchecked")
    List<String> projects = (List<String>) result.get("projects");
    platform = Platform.valueOf(platformStr);
    final Runtime runtime = Runtime.getRuntime();
    File pidsForder = new File("./pids");
    if (!pidsForder.exists()) {
        pidsForder.mkdir();
    } else {
        File[] files = pidsForder.listFiles();
        if (files != null) {
            for (File f : files) {
                f.deleteOnExit();
                String pidStr = f.getName();
                try {
                    Long pid = new Long(pidStr);
                    if (Processes.isProcessRunning(platform, pid)) {
                        if (Platform.Windows == platform) {
                            Processes.tryKillProcess(null, platform, new NullProcessor(), pid);
                        } else {
                            Processes.killProcess(null, platform, new NullProcessor(), pid);
                        }

                    }
                } catch (Exception ex) {
                }
            }
        }
    }

    File currentForder = new File("");
    String rootPath = currentForder.getAbsolutePath();
    rootPath = rootPath.replace(File.separator + "build" + File.separator + "libs", "");
    rootPath = rootPath.replace(File.separator + "e-example-ms-start-w", "");

    for (String value : projects) {
        String path = value;
        String[] values = value.split("/");
        value = values[values.length - 1];
        String appName = value;
        value = rootPath + "/" + path + "/build/libs/" + value + "-" + version + ".jar";

        JMenuItem menuItem = new JMenuItem(appName);
        JTextArea textArea = new JTextArea();
        textArea.setVisible(true);
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        textArea.setAutoscrolls(true);
        JScrollPane scorll = new JScrollPane(textArea);
        this.textSreaMap.put(appName, scorll);
        EComposite ecomposite = new EComposite();
        ecomposite.setCommand(value);
        ecomposite.setTextArea(textArea);
        composites.put(appName, ecomposite);
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Collection<JScrollPane> values = textSreaMap.values();
                for (JScrollPane t : values) {
                    t.setVisible(false);
                }
                String actions = e.getActionCommand();
                JScrollPane textArea = textSreaMap.get(actions);
                if (textArea != null) {
                    textArea.setVisible(true);
                    panel.removeAll();
                    panel.add(textArea);
                    panel.repaint();
                    panel.validate();
                    self.repaint();
                    self.validate();
                }
            }
        });
        menu.add(menuItem);
    }

    new Thread(new Runnable() {
        @Override
        public void run() {
            int size = composites.keySet().size();
            int index = 1;
            for (String appName : composites.keySet()) {
                EComposite composite = composites.get(appName);
                try {

                    Process process = runtime.exec(
                            "java " + jvmOption + " -Dfile.encoding=UTF-8 -jar " + composite.getCommand());
                    Long pid = Processes.processId(process);
                    pids.add(pid);
                    File pidsFile = new File("./pids", pid.toString());
                    pidsFile.createNewFile();

                    new WriteLogThread(process.getInputStream(), composite.getTextArea()).start();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                synchronized (lock) {
                    try {
                        if (index < size) {
                            lock.wait();
                        } else {
                            index++;
                        }

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }).start();

}

From source file:XMLWriteTest.java

public XMLWriteFrame() {
    setTitle("XMLWriteTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    chooser = new JFileChooser();

    // add component to frame

    comp = new RectangleComponent();
    add(comp);// w w w . jav  a 2  s  .c o m

    // set up menu bar

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu menu = new JMenu("File");
    menuBar.add(menu);

    JMenuItem newItem = new JMenuItem("New");
    menu.add(newItem);
    newItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            comp.newDrawing();
        }
    });

    JMenuItem saveItem = new JMenuItem("Save with DOM/XSLT");
    menu.add(saveItem);
    saveItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                saveDocument();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(XMLWriteFrame.this, e.toString());
            }
        }
    });

    JMenuItem saveStAXItem = new JMenuItem("Save with StAX");
    menu.add(saveStAXItem);
    saveStAXItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                saveStAX();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(XMLWriteFrame.this, e.toString());
            }
        }
    });

    JMenuItem exitItem = new JMenuItem("Exit");
    menu.add(exitItem);
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });
}

From source file:MenuDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;//w ww  . java 2  s . co  m
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;

    //Create the menu bar.
    menuBar = new JMenuBar();

    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T);
    //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    ImageIcon icon = createImageIcon("images/1.gif");
    menuItem = new JMenuItem("Both text and icon", icon);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem(icon);
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    //a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();

    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    //a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    //a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);

    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
    menuItem.addActionListener(this);
    submenu.add(menuItem);

    menuItem = new JMenuItem("Another item");
    menuItem.addActionListener(this);
    submenu.add(menuItem);
    menu.add(submenu);

    //Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
    menuBar.add(menu);

    return menuBar;
}

From source file:jmap2gml.ScriptGui.java

/**
 * Formats the window, initializes the JMap2Script object, and sets up all
 * the necessary events.//from  ww w. j  a  v  a  2s .c o m
 */
public ScriptGui() {
    setTitle("jmap to gml script converter");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    getContentPane().setLayout(new GridBagLayout());

    this.addWindowListener(new WindowListener() {
        @Override
        public void windowOpened(WindowEvent we) {
        }

        @Override
        public void windowClosing(WindowEvent we) {
            saveConfig();
        }

        @Override
        public void windowClosed(WindowEvent we) {
        }

        @Override
        public void windowIconified(WindowEvent we) {
        }

        @Override
        public void windowDeiconified(WindowEvent we) {
        }

        @Override
        public void windowActivated(WindowEvent we) {
        }

        @Override
        public void windowDeactivated(WindowEvent we) {
        }
    });

    GridBagConstraints c = new GridBagConstraints();

    setResizable(true);
    setIconImage((new ImageIcon("spikeup.png")).getImage());

    jta = new JTextArea(38, 30);

    loadConfig();

    JScrollPane jsp = new JScrollPane(jta);
    jsp.setRowHeaderView(new TextLineNumber(jta));
    jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    jsp.setSize(jsp.getWidth(), 608);

    // menu bar
    JMenuBar menubar = new JMenuBar();

    // file menu
    JMenu file = new JMenu("File");

    // load button
    JMenuItem load = new JMenuItem("Load jmap");
    load.addActionListener(ae -> {
        JFileChooser fileChooser = new JFileChooser(prevDirectory);
        fileChooser.setFileFilter(new FileNameExtensionFilter("jmap file", "jmap", "jmap"));

        int returnValue = fileChooser.showOpenDialog(null);

        if (returnValue == JFileChooser.APPROVE_OPTION) {
            File selectedFile = fileChooser.getSelectedFile();

            prevDirectory = selectedFile.getAbsolutePath();

            jm2s = new ScriptFromJmap(selectedFile.getPath(), false);

            jta.setText("");
            jta.append(jm2s.toString());
            jta.setCaretPosition(0);

            writeFile.setEnabled(true);

            drawPanel.setItems(jta.getText().split("\n"));
        }
    });

    // add load to file menu
    file.add(load);

    // button to save script to file
    writeFile = new JMenuItem("Write file");
    writeFile.addActionListener(ae -> {
        if (jm2s != null) {
            PrintWriter out;
            try {
                File f = new File(
                        jm2s.getFileName().substring(0, jm2s.getFileName().lastIndexOf(".jmap")) + ".gml");
                out = new PrintWriter(f);
                out.append(jm2s.toString());
                out.close();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    writeFile.setEnabled(false);

    JMenuItem gmx = new JMenuItem("Export as gmx");
    gmx.addActionListener(ae -> {
        String fn = String.format("%s.room.gmx", prevDirectory);

        JFileChooser fc = new JFileChooser(prevDirectory);
        fc.setSelectedFile(new File(fn));
        fc.setFileFilter(new FileNameExtensionFilter("Game Maker XML", "gmx", "gmx"));
        fc.showDialog(null, "Save");
        File f = fc.getSelectedFile();

        if (f != null) {
            try {
                GMX.itemsToGMX(drawPanel.items, new FileOutputStream(f));
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });

    // add to file menu
    file.add(writeFile);
    file.add(gmx);

    // add file menu to the menubar
    menubar.add(file);

    // Edit menu

    // display menu
    JMenu display = new JMenu("Display");

    JMenuItem update = new JMenuItem("Update");

    update.addActionListener(ae -> {
        drawPanel.setItems(jta.getText().split("\n"));
    });

    display.add(update);

    JMenuItem gridToggle = new JMenuItem("Toggle Grid");
    gridToggle.addActionListener(ae -> {
        drawPanel.toggleGrid();
    });
    display.add(gridToggle);

    JMenuItem gridOptions = new JMenuItem("Modify Grid");
    gridOptions.addActionListener(ae -> {
        drawPanel.modifyGrid();
    });
    display.add(gridOptions);

    menubar.add(display);

    // sets the menubar
    setJMenuBar(menubar);

    // add the text area to the window
    c.gridx = 0;
    c.gridy = 0;
    add(jsp, c);

    // initialize the preview panel
    drawPanel = new Preview(this);
    JScrollPane scrollPane = new JScrollPane(drawPanel);

    // add preview panel to the window
    c.gridx = 1;
    c.gridwidth = 2;
    add(scrollPane, c);

    pack();
    setMinimumSize(this.getSize());
    setLocationRelativeTo(null);
    setVisible(true);
    drawPanel.setItems(jta.getText().split("\n"));
}

From source file:it.unibas.spicygui.vista.QueryTabbedPane.java

public void creaPopUp() {
    this.popUpMenu = new JPopupMenu();
    this.popUpMenu.add(new ActionIncreaseFont(textArea));
    this.popUpMenu.add(new ActionDecreaseFont(textArea));
    this.popUpMenu.add(new ActionExportQuery(textArea));
    if (xQuery) {
        MappingTask mappingTask = scenario.getMappingTask();
        if (mappingTask.getSourceProxy().getType().equalsIgnoreCase(SpicyEngineConstants.TYPE_XML)) {
            JMenu jMenu = new JMenu(NbBundle.getMessage(Costanti.class, Costanti.ACTION_EXECUTE_XQUERY));
            this.popUpMenu.add(jMenu);
            List<String> sourceInstancesName = (List<String>) mappingTask.getSourceProxy()
                    .getAnnotation(SpicyEngineConstants.XML_INSTANCE_FILE_LIST);
            for (String instance : sourceInstancesName) {
                jMenu.add(new ActionExecuteXQuery(instance, scenario.getMappingTask()));
            }//from  w  ww.j ava  2s  .c  om
        }
    } else {
        this.popUpMenu.add(new ActionExecuteSql(textArea, scenario.getMappingTask()));
    }
    this.textArea.addMouseListener(new PopUpListener());
}

From source file:J3dSwingFrame.java

/**
 * Construct the test frame with a menubar and 3D canvas
 *//*from  w w  w .  j a va2 s. co  m*/
public J3dSwingFrame() {
    super("Java3D Tester");

    // Disable lightweight menus
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);

    JMenuBar menubar = new JMenuBar();

    // File menu
    JMenu file_menu = new JMenu("File");
    menubar.add(file_menu);

    close_menu = new JMenuItem("Exit");
    close_menu.addActionListener(this);
    file_menu.add(close_menu);

    setJMenuBar(menubar);

    GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice device = env.getDefaultScreenDevice();
    GraphicsConfiguration config = device.getBestConfiguration(template);

    canvas = new Canvas3D(config);

    // add the canvas to this frame. Since this is the only thing added to
    // the main frame we don't care about layout managers etc.

    getContentPane().add(canvas, "Center");

    constructWorld();

    setSize(600, 600);
}