/** Return a menu for DesktopWindow and add a special listener. */ public static JMenu getCurrencyMenu(ActionListener listener) { JRadioButtonMenuItem menuItem; String defaultCurrency = Money.getCurrencyFor(Money.getDefaultCurrency()); JMenu menu = new JMenu("Währung"); ButtonGroup group = new ButtonGroup(); JMenu europeanMenu = new JMenu("Europa"); String europeanCurrencies[] = Money.getEuropeanCurrencyList(); for (int i = 0; i < europeanCurrencies.length; i++) { menuItem = new RadioCurrencyMenuItem(europeanCurrencies[i]); menuItem.addActionListener(listener); europeanMenu.add(menuItem); group.add(menuItem); if (europeanCurrencies[i].startsWith(defaultCurrency)) { menuItem.setSelected(true); } if (i == 0) { europeanMenu.addSeparator(); } } menu.add(europeanMenu); return menu; }
public void createPopupMenu() { super.createPopupMenu(); JPopupMenu popupMenu = getPopupMenu(); if (popupMenu == null) { popupMenu = new JPopupMenu(); setPopupMenu(popupMenu); } else { popupMenu.addSeparator(); } propertiesItem = new JMenuItem("Properties ..."); propertiesItem.addActionListener(this); propertiesItem.setMnemonic('s'); popupMenu.add(propertiesItem); popupMenu.addSeparator(); ButtonGroup group = new ButtonGroup(); inItem = new JRadioButtonMenuItem("IN"); group.add(inItem); inItem.addActionListener(this); popupMenu.add(inItem); outItem = new JRadioButtonMenuItem("OUT"); group.add(outItem); outItem.addActionListener(this); popupMenu.add(outItem); inoutItem = new JRadioButtonMenuItem("INOUT"); group.add(inoutItem); inoutItem.addActionListener(this); popupMenu.add(inoutItem); }
public void changeDictionary(String strLanguage) { // Change dictionary MonitorDictionary.setCurrentLanguage(strLanguage); DefaultDictionary.setCurrentLanguage(strLanguage); ErrorDictionary.setCurrentLanguage(strLanguage); // Update UI updateLanguage(); WindowManager.updateLanguage(); int iIndex = mvtLanguage.indexOf(strLanguage); if (iIndex >= 0) { JRadioButtonMenuItem mnu = (JRadioButtonMenuItem) mvtLanguageItem.elementAt(iIndex); mnu.setSelected(true); } // Store config Hashtable prt = null; try { prt = Global.loadHashtable(Global.FILE_CONFIG); } catch (Exception e) { prt = new Hashtable(); } prt.put("Language", strLanguage); try { Global.storeHashtable(prt, Global.FILE_CONFIG); } catch (Exception e) { } }
private ButtonGroup createButtonGroup() { ButtonGroup g1 = new ButtonGroup(); for (int j = 0; j < 4; j++) for (int i = 0; i < 16; i++) { JRadioButtonMenuItem b = new JRadioButtonMenuItem(new PopupIcon(i + 16 * j)); b.setSelectedIcon(null); b.addActionListener(this::doSelect); this.add(b); g1.add(b); } return g1; }
/** Creates a JRadioButtonMenuItem for the Themes menu */ private JMenuItem createThemesMenuItem( JMenu menu, String label, char mnemonic, String accessibleDescription, DefaultMetalTheme theme) { JRadioButtonMenuItem mi = (JRadioButtonMenuItem) menu.add(new JRadioButtonMenuItem(label)); themesMenuGroup.add(mi); mi.setMnemonic(mnemonic); mi.getAccessibleContext().setAccessibleDescription(accessibleDescription); mi.addActionListener(new ChangeThemeAction(this, theme)); return mi; }
/** * This method initializes jRadioButtonMenuItem1 * * @return JRadioButtonMenuItem */ private JRadioButtonMenuItem getJRadioButtonMenuItem1() { if (jRadioButtonMenuItem1 == null) { jRadioButtonMenuItem1 = new JRadioButtonMenuItem(); jRadioButtonMenuItem1.setText("System"); jRadioButtonMenuItem1.setMnemonic(java.awt.event.KeyEvent.VK_Y); jRadioButtonMenuItem1.setAccelerator( javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_Y, java.awt.Event.ALT_MASK, false)); jRadioButtonMenuItem1.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { changeLnF(UIManager.getSystemLookAndFeelClassName()); } }); } return jRadioButtonMenuItem1; }
public TreeElementMenu( MainFrame _frame, TopiaryWindow _parent, String name, ColorPanel _colorPanel, int elementType) { super(name); parent = _parent; frame = _frame; tree = ((TreeWindow) parent).tree; noColoringMenuItem.addActionListener(this); add(noColoringMenuItem); majorityColoringMenuItem.addActionListener(this); add(majorityColoringMenuItem); colorBy = new ColorByMenu(frame, parent, _colorPanel, elementType); add(colorBy); }
/** * This method initializes jRadioButtonMenuItem * * @return JRadioButtonMenuItem */ private JRadioButtonMenuItem getJRadioButtonMenuItem() { if (jRadioButtonMenuItem == null) { jRadioButtonMenuItem = new JRadioButtonMenuItem(); jRadioButtonMenuItem.setText("Default"); jRadioButtonMenuItem.setSelected(true); jRadioButtonMenuItem.setAccelerator( javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_D, java.awt.Event.ALT_MASK, false)); jRadioButtonMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_D); jRadioButtonMenuItem.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { changeLnF(UIManager.getCrossPlatformLookAndFeelClassName()); } }); } return jRadioButtonMenuItem; }
/* * Called before a popup menu is activated and is used to enable or * disable menu items according to the state of the activity. */ public void preparePopupMenu() { super.preparePopupMenu(); if ( /*DataTypeUtils.getReferenceClass(getData()) != null && */ (((getActivity().getApplication() != null)) || getActivity().getImplementationType().equals(ImplementationType.Manual))) { propertiesItem.setEnabled(true); } else { propertiesItem.setEnabled(false); } if (Direction.IN == direction) { inItem.setSelected(true); } else if (Direction.OUT == direction) { outItem.setSelected(true); } else if (Direction.IN_OUT == direction) { inoutItem.setSelected(true); } }
private static JRadioButtonMenuItem createLookAndFeelItem( String lafName, String lafClassName, final ButtonGroup lookAndFeelRadioGroup) { JRadioButtonMenuItem lafItem = new JRadioButtonMenuItem(); lafItem.setSelected(lafClassName.equals(lookAndFeel)); lafItem.setHideActionText(true); lafItem.setAction( new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { ButtonModel m = lookAndFeelRadioGroup.getSelection(); try { setLookAndFeel(m.getActionCommand()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } } }); lafItem.setText(lafName); lafItem.setActionCommand(lafClassName); lookAndFeelRadioGroup.add(lafItem); return lafItem; }
private JMenuBar createMenuBar() { JMenu menu = new JMenu("Menu"); disablingItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.ALT_MASK)); menu.add(disablingItem); menu.addSeparator(); blurItem.setSelected(true); blurItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, InputEvent.ALT_MASK)); menu.add(blurItem); embossItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, InputEvent.ALT_MASK)); menu.add(embossItem); busyPainterItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, InputEvent.ALT_MASK)); menu.add(busyPainterItem); ButtonGroup group = new ButtonGroup(); group.add(blurItem); group.add(embossItem); group.add(busyPainterItem); ItemListener menuListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (blurItem.isSelected()) { // layer.setUI(blurUI); } else if (embossItem.isSelected()) { // layer.setUI(embossUI); } else if (busyPainterItem.isSelected()) { layer.setUI(busyPainterUI); } } }; blurItem.addItemListener(menuListener); embossItem.addItemListener(menuListener); busyPainterItem.addItemListener(menuListener); // embossUI.getUnlockButton().addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent e) { // disablingItem.doClick(); // } // }); JMenuBar bar = new JMenuBar(); bar.add(menu); bar.add(new LafMenu()); return bar; }
/** * Create a JFSstat demo. * * @param jkstat a JKstat object * @param standalone if false, indicates that this demo is being called from another application */ public JFSstat(JKstat jkstat, boolean standalone) { super("jfsstat", standalone); mainPanel = new JFSstatPanel(jkstat, DEFAULT_INTERVAL); setContentPane(mainPanel); addInfoPanel(mainPanel, sversion); displayset = new HashSet<JRadioButtonMenuItem>(); JMenu displayMenu = new JMenu(SolViewResources.getString("FSSTAT.DISPLAY.TEXT")); displayMenu.setMnemonic(KeyEvent.VK_D); String curtitle = mainPanel.currentTitle(); ButtonGroup displayGroup = new ButtonGroup(); for (String title : mainPanel.titles()) { JRadioButtonMenuItem jmis = new JRadioButtonMenuItem(title, title.equals(curtitle)); displayMenu.add(jmis); displayGroup.add(jmis); displayset.add(jmis); jmis.addActionListener(this); } addMenu(displayMenu); JMenu showMenu = new JMenu(SolViewResources.getString("FSSTAT.SHOW.TEXT")); showMenu.setMnemonic(KeyEvent.VK_S); hiddenItem = new JCheckBoxMenuItem(SolViewResources.getString("FSSTAT.HIDDEN.TEXT"), false); hiddenItem.addActionListener(this); showMenu.add(hiddenItem); aggrItem = new JCheckBoxMenuItem(SolViewResources.getString("FSSTAT.FSTYPE.TEXT"), false); aggrItem.addActionListener(this); showMenu.add(aggrItem); addMenu(showMenu); setSize(620, 250); validate(); setVisible(true); }
/** * Create the Sleep for... Menu. * * @return the Sleep Menu */ protected JMenu sleepMenu() { JMenu jms = new JMenu(KstatResources.getString("SLEEP.TEXT")); jms.setMnemonic(KeyEvent.VK_U); sleepItem1 = new JRadioButtonMenuItem(KstatResources.getString("SLEEP.1")); sleepItem1.addActionListener(this); sleepItem2 = new JRadioButtonMenuItem(KstatResources.getString("SLEEP.2")); sleepItem2.addActionListener(this); sleepItem5 = new JRadioButtonMenuItem(KstatResources.getString("SLEEP.5"), true); sleepItem5.addActionListener(this); sleepItem10 = new JRadioButtonMenuItem(KstatResources.getString("SLEEP.10")); sleepItem10.addActionListener(this); jms.add(sleepItem1); jms.add(sleepItem2); jms.add(sleepItem5); jms.add(sleepItem10); ButtonGroup sleepGroup = new ButtonGroup(); sleepGroup.add(sleepItem1); sleepGroup.add(sleepItem2); sleepGroup.add(sleepItem5); sleepGroup.add(sleepItem10); return jms; }
/** Builds the MenuBar */ private void buildUI() { // Construct menu items JMenu lookAndFeel = new JMenu("Look and feel"); JRadioButtonMenuItem nativeLaF = new JRadioButtonMenuItem("Native", true); JRadioButtonMenuItem javaLaF = new JRadioButtonMenuItem("Java (Metal)"); JRadioButtonMenuItem motifLaF = new JRadioButtonMenuItem("Motif"); JMenu help = new JMenu("Help"); JMenuItem about = new JMenuItem("About"); // Add menu items to menu bar add(lookAndFeel); lookAndFeel.add(nativeLaF); lookAndFeel.add(javaLaF); lookAndFeel.add(motifLaF); add(Box.createHorizontalGlue()); add(help); help.add(about); // Add buttons to button group ButtonGroup laFGroup = new ButtonGroup(); laFGroup.add(nativeLaF); laFGroup.add(javaLaF); laFGroup.add(motifLaF); // Set action listeners nativeLaF.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { UIUtilities.setLookAndFeel(owner, UIManager.getSystemLookAndFeelClassName()); owner.pack(); } }); javaLaF.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { UIUtilities.setLookAndFeel(owner, UIManager.getCrossPlatformLookAndFeelClassName()); owner.pack(); } }); motifLaF.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { UIUtilities.setLookAndFeel(owner, "com.sun.java.swing.plaf.motif.MotifLookAndFeel"); owner.pack(); } }); about.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { UIUtilities.showAboutDialog(owner); } }); }
protected JMenu buildSpeedMenu() { JMenu speed = new JMenu("Drag"); JRadioButtonMenuItem live = new JRadioButtonMenuItem("Live"); JRadioButtonMenuItem outline = new JRadioButtonMenuItem("Outline"); JRadioButtonMenuItem slow = new JRadioButtonMenuItem("Old and Slow"); ButtonGroup group = new ButtonGroup(); group.add(live); group.add(outline); group.add(slow); live.setSelected(true); slow.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // for right now I'm saying if you set the mode // to something other than a specified mode // it will revert to the old way // This is mostly for comparison's sake desktop.setDragMode(-1); } }); live.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { desktop.setDragMode(JDesktopPane.LIVE_DRAG_MODE); } }); outline.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); } }); speed.add(live); speed.add(outline); speed.add(slow); return speed; }
public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("No coloring")) { ((TreeWindow) parent).removeColor(); } else if (e.getActionCommand().equals("Majority coloring")) { ((TreeWindow) parent).tree.setMajorityColoring(majorityColoringMenuItem.isSelected()); ((TreeWindow) parent).tree.getTree().updateBranchColorFromChildren(); // frame.recolorBranches(); } else if (e.getActionCommand().equals("Number of OTUs")) { tree.getTree().sortByNumberOfOtus(); tree.setYOffsets(tree.getTree(), 0); tree.setTOffsets(tree.getTree(), 0); tree.setROffsets(tree.getTree(), 0); tree.setRadialOffsets(tree.getTree()); } else if (e.getActionCommand().equals("Number of immediate children")) { tree.getTree().sortByNumberOfChildren(); tree.setYOffsets(tree.getTree(), 0); tree.setTOffsets(tree.getTree(), 0); tree.setROffsets(tree.getTree(), 0); tree.setRadialOffsets(tree.getTree()); } }
/** Called when a choice was made in the animation type combo box. */ public void animationCombo_actionPerformed() { int selectedIndex = animationCombo.getSelectedIndex(); switch (selectedIndex) { case HackController.DISPLAY_CHANGES: if (!partAnimMenuItem.isSelected()) partAnimMenuItem.setSelected(true); break; case HackController.ANIMATION: if (!fullAnimMenuItem.isSelected()) fullAnimMenuItem.setSelected(true); break; case HackController.NO_DISPLAY_CHANGES: if (!noAnimMenuItem.isSelected()) noAnimMenuItem.setSelected(true); break; } notifyControllerListeners(ControllerEvent.ANIMATION_MODE_CHANGE, new Integer(selectedIndex)); }
/** Called when a choice was made in the numeric format combo box. */ public void formatCombo_actionPerformed() { int selectedIndex = formatCombo.getSelectedIndex(); switch (selectedIndex) { case HackController.DECIMAL_FORMAT: if (!decMenuItem.isSelected()) decMenuItem.setSelected(true); break; case HackController.HEXA_FORMAT: if (!hexaMenuItem.isSelected()) hexaMenuItem.setSelected(true); break; case HackController.BINARY_FORMAT: if (!binMenuItem.isSelected()) binMenuItem.setSelected(true); break; } notifyControllerListeners(ControllerEvent.NUMERIC_FORMAT_CHANGE, selectedIndex); }
private JComponent createToolPanel() { JComponent box = Box.createVerticalBox(); JCheckBox button = new JCheckBox(disablingItem.getText()); button.setModel(disablingItem.getModel()); box.add(Box.createGlue()); box.add(button); box.add(Box.createGlue()); JRadioButton blur = new JRadioButton(blurItem.getText()); blur.setModel(blurItem.getModel()); box.add(blur); JRadioButton emboss = new JRadioButton(embossItem.getText()); emboss.setModel(embossItem.getModel()); box.add(emboss); JRadioButton translucent = new JRadioButton(busyPainterItem.getText()); translucent.setModel(busyPainterItem.getModel()); box.add(translucent); box.add(Box.createGlue()); return box; }
/** Called when a choice was made in the additional display combo box. */ public void additionalDisplayCombo_actionPerformed() { int selectedIndex = additionalDisplayCombo.getSelectedIndex(); switch (selectedIndex) { case HackController.SCRIPT_ADDITIONAL_DISPLAY: if (!scriptMenuItem.isSelected()) scriptMenuItem.setSelected(true); break; case HackController.OUTPUT_ADDITIONAL_DISPLAY: if (!outputMenuItem.isSelected()) outputMenuItem.setSelected(true); break; case HackController.COMPARISON_ADDITIONAL_DISPLAY: if (!compareMenuItem.isSelected()) compareMenuItem.setSelected(true); break; case HackController.NO_ADDITIONAL_DISPLAY: if (!noAdditionalDisplayMenuItem.isSelected()) noAdditionalDisplayMenuItem.setSelected(true); break; } notifyControllerListeners( ControllerEvent.ADDITIONAL_DISPLAY_CHANGE, new Integer(selectedIndex)); }
public Check() { super( "Substance test with very very very very very very very very very very very very very very long title"); final ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) { setIconImage( SubstanceLogo.getLogoImage( SubstanceLookAndFeel.getCurrentSkin(this.getRootPane()) .getColorScheme( DecorationAreaType.PRIMARY_TITLE_PANE, ColorSchemeAssociationKind.FILL, ComponentState.ENABLED))); } SubstanceLookAndFeel.registerSkinChangeListener( new SkinChangeListener() { @Override public void skinChanged() { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { setIconImage( SubstanceLogo.getLogoImage( SubstanceLookAndFeel.getCurrentSkin(Check.this.getRootPane()) .getColorScheme( DecorationAreaType.PRIMARY_TITLE_PANE, ColorSchemeAssociationKind.FILL, ComponentState.ENABLED))); } }); } }); setLayout(new BorderLayout()); jtp = new JTabbedPane(); try { mainTabPreviewPainter = new MyMainTabPreviewPainter(); jtp.putClientProperty(LafWidget.TABBED_PANE_PREVIEW_PAINTER, mainTabPreviewPainter); } catch (Throwable e) { } jtp.getModel().addChangeListener(new TabSwitchListener()); final JXPanel jxPanel = new JXPanel(new BorderLayout()); toolbar = getToolbar("", 22, true); jxPanel.add(toolbar, BorderLayout.NORTH); JXStatusBar statusBar = getStatusBar(jxPanel, jtp); this.add(statusBar, BorderLayout.SOUTH); taskPaneContainer = new JXTaskPaneContainer() { @Override public boolean getScrollableTracksViewportWidth() { return false; } }; taskPaneContainer.setScrollableTracksViewportHeight(false); taskPaneContainer.setScrollableTracksViewportWidth(false); mainTaskPane = new JXTaskPane(); mainTaskPane.setLayout(new BorderLayout()); JPanel mainControlPanel = ControlPanelFactory.getMainControlPanel(this, jtp, mainTabPreviewPainter, toolbar); // mainControlPanel.setOpaque(false); mainTaskPane.add(mainControlPanel, BorderLayout.CENTER); mainTaskPane.setTitle("General settings"); mainTaskPane.setIcon(getIcon("JFrameColor16")); mainTaskPane.setCollapsed(true); taskPaneContainer.add(mainTaskPane); JPanel dialogControlPanel = ControlPanelFactory.getDialogControlPanel(this); JXTaskPane dialogTaskPane = new JXTaskPane(); dialogTaskPane.setLayout(new BorderLayout()); dialogTaskPane.add(dialogControlPanel, BorderLayout.CENTER); dialogTaskPane.setTitle("Frames & Dialogs"); dialogTaskPane.setIcon(getIcon("JDialogColor16")); dialogTaskPane.setCollapsed(true); // dialogTaskPane.setOpaque(false); taskPaneContainer.add(dialogTaskPane); currentSpecificTaskPane = null; final JScrollPane scrollPane = new JScrollPane( taskPaneContainer, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); SubstanceLookAndFeel.setDecorationType(scrollPane, DecorationAreaType.GENERAL); // scrollPane.setOpaque(false); // scrollPane.getViewport().setOpaque(false); JPanel mainPanel = new JPanel(); mainPanel.add(scrollPane); mainPanel.add(jtp); mainPanel.setLayout( new LayoutManager() { @Override public void addLayoutComponent(String name, Component comp) {} @Override public Dimension minimumLayoutSize(Container parent) { Dimension min1 = scrollPane.getMinimumSize(); Dimension min2 = jtp.getMinimumSize(); return new Dimension(min1.width + min2.width, min1.height + min2.height); } @Override public void layoutContainer(Container parent) { // give 30% width to task pane container and // 70% width to the tabbed pane with controls. int width = parent.getWidth(); int height = parent.getHeight(); scrollPane.setBounds(0, 0, (int) (0.3 * width), height); jtp.setBounds((int) (0.3 * width), 0, width - (int) (0.3 * width), height); } @Override public Dimension preferredLayoutSize(Container parent) { Dimension pref1 = scrollPane.getPreferredSize(); Dimension pref2 = jtp.getPreferredSize(); return new Dimension(pref1.width + pref2.width, pref1.height + pref2.height); } @Override public void removeLayoutComponent(Component comp) {} }); jxPanel.add(mainPanel, BorderLayout.CENTER); this.add(jxPanel, BorderLayout.CENTER); setPreferredSize(new Dimension(400, 400)); this.setSize(getPreferredSize()); setMinimumSize(getPreferredSize()); ButtonsPanel buttonsPanel = new ButtonsPanel(); jtp.addTab("Buttons", getIcon("JButtonColor16"), buttonsPanel); getRootPane().setDefaultButton(buttonsPanel.defaultButton); jtp.addTab("Combo box", getIcon("JComboBoxColor16"), new CombosPanel()); jtp.addTab("Scroll pane", getIcon("JScrollPaneColor16"), new ScrollPanel()); TabCloseCallback closeCallback = new TabCloseCallback() { @Override public TabCloseKind onAreaClick( JTabbedPane tabbedPane, int tabIndex, MouseEvent mouseEvent) { if (mouseEvent.getButton() != MouseEvent.BUTTON3) return TabCloseKind.NONE; if (mouseEvent.isShiftDown()) { return TabCloseKind.ALL; } return TabCloseKind.THIS; } @Override public TabCloseKind onCloseButtonClick( JTabbedPane tabbedPane, int tabIndex, MouseEvent mouseEvent) { if (mouseEvent.isAltDown()) { return TabCloseKind.ALL_BUT_THIS; } if (mouseEvent.isShiftDown()) { return TabCloseKind.ALL; } return TabCloseKind.THIS; } @Override public String getAreaTooltip(JTabbedPane tabbedPane, int tabIndex) { return null; } @Override public String getCloseButtonTooltip(JTabbedPane tabbedPane, int tabIndex) { StringBuffer result = new StringBuffer(); result.append("<html><body>"); result.append("Mouse click closes <b>" + tabbedPane.getTitleAt(tabIndex) + "</b> tab"); result.append( "<br><b>Alt</b>-Mouse click closes all tabs but <b>" + tabbedPane.getTitleAt(tabIndex) + "</b> tab"); result.append("<br><b>Shift</b>-Mouse click closes all tabs"); result.append("</body></html>"); return result.toString(); } }; try { TabPanel tp = new TabPanel(); tp.jtp.putClientProperty(SubstanceLookAndFeel.TABBED_PANE_CLOSE_CALLBACK, closeCallback); jtp.addTab("Tabs", getIcon("JTabbedPaneColor16"), tp); } catch (NoClassDefFoundError ncdfe) { } jtp.addTab("Split", new SplitPanel()); jtp.addTab("Desktop", getIcon("JDesktopPaneColor16"), new DesktopPanel()); jtp.addTab("Text fields", getIcon("JTextPaneColor16"), new TextFieldsPanel()); jtp.addTab("Table", getIcon("JTableColor16"), new TablePanel()); try { jtp.addTab("List", getIcon("JListColor16"), new ListPanel()); } catch (NoClassDefFoundError ncdfe) { } jtp.addTab("Slider", getIcon("JSliderColor16"), new SliderPanel()); jtp.addTab("Progress bar", getIcon("JProgressBarColor16"), new ProgressBarPanel()); jtp.addTab("Spinner", getIcon("JSpinnerColor16"), new SpinnerPanel()); jtp.addTab("Tree", getIcon("JTreeColor16"), new TreePanel()); jtp.addTab("File tree", getIcon("JTreeColor16"), new FileTreePanel()); jtp.addTab("Cards", new CardPanel()); JPanel verticalButtonPanel = new JPanel(); verticalButtonPanel.setLayout(new GridLayout(1, 3)); verticalButtonPanel.add(new JButton("Vert button 1")); verticalButtonPanel.add(new JButton("Vert button 2")); JPanel smallVerticalButtonPanel = new JPanel(); smallVerticalButtonPanel.setLayout(new GridLayout(4, 4)); for (int row = 0; row < 4; row++) { for (int col = 0; col < 4; col++) { JButton vertButton = new JButton("vert"); vertButton.setToolTipText("Vertical button " + row + ":" + col); smallVerticalButtonPanel.add(vertButton); } } verticalButtonPanel.add(smallVerticalButtonPanel); jtp.addTab("V-Buttons", verticalButtonPanel); jtp.addTab("Colored", new ColoredControlsPanel()); jtp.addTab("Colorized", new ColorizedControlsPanel()); jtp.addTab("Cells", new CellsPanel()); jtp.addTab("Sizes", new SizesPanel()); jtp.addTab("H-Align", new HAlignmentPanel()); jtp.addTab("V-Align", new VAlignmentPanel()); // sample menu bar JMenuBar jmb = new JMenuBar(); if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) { jmb.add(SampleMenuFactory.getSkinMenu()); jmb.add(SampleMenuFactory.getTransformMenu()); } JMenu coloredMenu = new JMenu("Colors"); coloredMenu.setMnemonic('0'); JMenuItem coloredMI = new JMenuItem("Italic red"); coloredMI.setFont(coloredMI.getFont().deriveFont(Font.ITALIC)); coloredMI.setForeground(Color.red); coloredMenu.add(coloredMI); JRadioButtonMenuItem coloredRBMI = new JRadioButtonMenuItem("Bold green"); coloredRBMI.setFont(coloredRBMI.getFont().deriveFont(Font.BOLD)); coloredRBMI.setForeground(Color.green); coloredMenu.add(coloredRBMI); JCheckBoxMenuItem coloredCBMI = new JCheckBoxMenuItem("Big blue"); coloredCBMI.setFont(coloredCBMI.getFont().deriveFont(32f)); coloredCBMI.setForeground(Color.blue); coloredMenu.add(coloredCBMI); JMenu coloredM = new JMenu("Always big magenta"); coloredM.setForeground(Color.magenta); coloredM.setFont(coloredM.getFont().deriveFont(24f)); coloredMenu.add(coloredM); jmb.add(coloredMenu); JMenu testMenu = SampleMenuFactory.getTestMenu(); jmb.add(testMenu); JMenu jm4 = new JMenu("Disabled"); jm4.add(new JMenuItem("dummy4")); jm4.setMnemonic('4'); jmb.add(jm4); jm4.setEnabled(false); // LAF changing jmb.add(SampleMenuFactory.getLookAndFeelMenu(this)); setJMenuBar(jmb); TabCloseCallback closeCallbackMain = new TabCloseCallback() { @Override public TabCloseKind onAreaClick( JTabbedPane tabbedPane, int tabIndex, MouseEvent mouseEvent) { if (mouseEvent.getButton() != MouseEvent.BUTTON2) return TabCloseKind.NONE; if (mouseEvent.isShiftDown()) { return TabCloseKind.ALL; } return TabCloseKind.THIS; } @Override public TabCloseKind onCloseButtonClick( JTabbedPane tabbedPane, int tabIndex, MouseEvent mouseEvent) { if (mouseEvent.isAltDown()) { return TabCloseKind.ALL_BUT_THIS; } if (mouseEvent.isShiftDown()) { return TabCloseKind.ALL; } return TabCloseKind.THIS; } @Override public String getAreaTooltip(JTabbedPane tabbedPane, int tabIndex) { return null; } @Override public String getCloseButtonTooltip(JTabbedPane tabbedPane, int tabIndex) { StringBuffer result = new StringBuffer(); result.append("<html><body>"); result.append("Mouse click closes <b>" + tabbedPane.getTitleAt(tabIndex) + "</b> tab"); result.append( "<br><b>Alt</b>-Mouse click closes all tabs but <b>" + tabbedPane.getTitleAt(tabIndex) + "</b> tab"); result.append("<br><b>Shift</b>-Mouse click closes all tabs"); result.append("</body></html>"); return result.toString(); } }; jtp.putClientProperty(SubstanceLookAndFeel.TABBED_PANE_CLOSE_CALLBACK, closeCallbackMain); SubstanceLookAndFeel.registerTabCloseChangeListener( new TabCloseListener() { @Override public void tabClosed(JTabbedPane tabbedPane, Component tabComponent) { out("Closed tab"); } @Override public void tabClosing(JTabbedPane tabbedPane, Component tabComponent) { out("Closing tab"); } }); SubstanceLookAndFeel.registerTabCloseChangeListener( jtp, new VetoableTabCloseListener() { @Override public void tabClosed(JTabbedPane tabbedPane, Component tabComponent) { out("Closed tab - specific"); } @Override public void tabClosing(JTabbedPane tabbedPane, Component tabComponent) { out("Closing tab - specific"); } @Override public boolean vetoTabClosing(JTabbedPane tabbedPane, Component tabComponent) { int userCloseAnswer = JOptionPane.showConfirmDialog( Check.this, "Are you sure you want to close '" + tabbedPane.getTitleAt(tabbedPane.indexOfComponent(tabComponent)) + "' tab?", "Confirm dialog", JOptionPane.YES_NO_OPTION); return (userCloseAnswer == JOptionPane.NO_OPTION); } }); SubstanceLookAndFeel.registerTabCloseChangeListener( jtp, new VetoableMultipleTabCloseListener() { @Override public void tabsClosed(JTabbedPane tabbedPane, Set<Component> tabComponents) { out("Closed " + tabComponents.size() + " tabs - specific"); } @Override public void tabsClosing(JTabbedPane tabbedPane, Set<Component> tabComponents) { out("Closing " + tabComponents.size() + " tabs - specific"); } @Override public boolean vetoTabsClosing(JTabbedPane tabbedPane, Set<Component> tabComponents) { int userCloseAnswer = JOptionPane.showConfirmDialog( Check.this, "Are you sure you want to close " + tabComponents.size() + " tabs?", "Confirm dialog", JOptionPane.YES_NO_OPTION); return (userCloseAnswer == JOptionPane.NO_OPTION); } }); addComponentListener( new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { System.out.println("Size " + getSize()); } }); }
/** Creates a menu bar. */ protected JMenuBar createMenuBar() { JMenu fileMenu = new JMenu("File"); JMenuItem menuItem; menuItem = new JMenuItem("Open"); menuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { JFileChooser fc = new JFileChooser(path); int result = fc.showOpenDialog(frame); if (result == JFileChooser.APPROVE_OPTION) { String newPath = fc.getSelectedFile().getPath(); new ComponentTree(newPath); } } }); fileMenu.add(menuItem); fileMenu.addSeparator(); menuItem = new JMenuItem("Exit"); menuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { System.exit(0); } }); fileMenu.add(menuItem); // Create a menu bar JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); // Menu for the look and feels (lafs). UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels(); ButtonGroup lafGroup = new ButtonGroup(); JMenu optionsMenu = new JMenu("Options"); menuBar.add(optionsMenu); for (int i = 0; i < lafs.length; i++) { JRadioButtonMenuItem rb = new JRadioButtonMenuItem(lafs[i].getName()); optionsMenu.add(rb); rb.setSelected(UIManager.getLookAndFeel().getName().equals(lafs[i].getName())); rb.putClientProperty("UIKey", lafs[i]); rb.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ae) { JRadioButtonMenuItem rb2 = (JRadioButtonMenuItem) ae.getSource(); if (rb2.isSelected()) { UIManager.LookAndFeelInfo info = (UIManager.LookAndFeelInfo) rb2.getClientProperty("UIKey"); try { UIManager.setLookAndFeel(info.getClassName()); SwingUtilities.updateComponentTreeUI(frame); } catch (Exception e) { System.err.println("unable to set UI " + e.getMessage()); } } } }); lafGroup.add(rb); } return menuBar; }
/** Adds the menu items to the menuber. */ protected void arrangeMenu() { // Build the first menu. fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu); viewMenu = new JMenu("View"); viewMenu.setMnemonic(KeyEvent.VK_V); menuBar.add(viewMenu); runMenu = new JMenu("Run"); runMenu.setMnemonic(KeyEvent.VK_R); menuBar.add(runMenu); // Build the second menu. helpMenu = new JMenu("Help"); helpMenu.setMnemonic(KeyEvent.VK_H); menuBar.add(helpMenu); programMenuItem = new JMenuItem("Load Program", KeyEvent.VK_O); programMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { programMenuItem_actionPerformed(); } }); fileMenu.add(programMenuItem); scriptMenuItem = new JMenuItem("Load Script", KeyEvent.VK_P); scriptMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scriptMenuItem_actionPerformed(); } }); fileMenu.add(scriptMenuItem); fileMenu.addSeparator(); exitMenuItem = new JMenuItem("Exit", KeyEvent.VK_X); exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK)); exitMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { exitMenuItem_actionPerformed(); } }); fileMenu.add(exitMenuItem); viewMenu.addSeparator(); ButtonGroup animationRadioButtons = new ButtonGroup(); animationSubMenu = new JMenu("Animate"); animationSubMenu.setMnemonic(KeyEvent.VK_A); viewMenu.add(animationSubMenu); partAnimMenuItem = new JRadioButtonMenuItem("Program flow"); partAnimMenuItem.setMnemonic(KeyEvent.VK_P); partAnimMenuItem.setSelected(true); partAnimMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { partAnimMenuItem_actionPerformed(); } }); animationRadioButtons.add(partAnimMenuItem); animationSubMenu.add(partAnimMenuItem); fullAnimMenuItem = new JRadioButtonMenuItem("Program & data flow"); fullAnimMenuItem.setMnemonic(KeyEvent.VK_D); fullAnimMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { fullAnimMenuItem_actionPerformed(); } }); animationRadioButtons.add(fullAnimMenuItem); animationSubMenu.add(fullAnimMenuItem); noAnimMenuItem = new JRadioButtonMenuItem("No Animation"); noAnimMenuItem.setMnemonic(KeyEvent.VK_N); noAnimMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { noAnimMenuItem_actionPerformed(); } }); animationRadioButtons.add(noAnimMenuItem); animationSubMenu.add(noAnimMenuItem); ButtonGroup additionalDisplayRadioButtons = new ButtonGroup(); additionalDisplaySubMenu = new JMenu("View"); additionalDisplaySubMenu.setMnemonic(KeyEvent.VK_V); viewMenu.add(additionalDisplaySubMenu); scriptDisplayMenuItem = new JRadioButtonMenuItem("Script"); scriptDisplayMenuItem.setMnemonic(KeyEvent.VK_S); scriptDisplayMenuItem.setSelected(true); scriptDisplayMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scriptDisplayMenuItem_actionPerformed(); } }); additionalDisplayRadioButtons.add(scriptDisplayMenuItem); additionalDisplaySubMenu.add(scriptDisplayMenuItem); outputMenuItem = new JRadioButtonMenuItem("Output"); outputMenuItem.setMnemonic(KeyEvent.VK_O); outputMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { outputMenuItem_actionPerformed(); } }); additionalDisplayRadioButtons.add(outputMenuItem); additionalDisplaySubMenu.add(outputMenuItem); compareMenuItem = new JRadioButtonMenuItem("Compare"); compareMenuItem.setMnemonic(KeyEvent.VK_C); compareMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { compareMenuItem_actionPerformed(); } }); additionalDisplayRadioButtons.add(compareMenuItem); additionalDisplaySubMenu.add(compareMenuItem); noAdditionalDisplayMenuItem = new JRadioButtonMenuItem("Screen"); noAdditionalDisplayMenuItem.setMnemonic(KeyEvent.VK_N); noAdditionalDisplayMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { noAdditionalDisplayMenuItem_actionPerformed(); } }); additionalDisplayRadioButtons.add(noAdditionalDisplayMenuItem); additionalDisplaySubMenu.add(noAdditionalDisplayMenuItem); ButtonGroup formatRadioButtons = new ButtonGroup(); numericFormatSubMenu = new JMenu("Format"); numericFormatSubMenu.setMnemonic(KeyEvent.VK_F); viewMenu.add(numericFormatSubMenu); decMenuItem = new JRadioButtonMenuItem("Decimal"); decMenuItem.setMnemonic(KeyEvent.VK_D); decMenuItem.setSelected(true); decMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { decMenuItem_actionPerformed(); } }); formatRadioButtons.add(decMenuItem); numericFormatSubMenu.add(decMenuItem); hexaMenuItem = new JRadioButtonMenuItem("Hexadecimal"); hexaMenuItem.setMnemonic(KeyEvent.VK_H); hexaMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { hexaMenuItem_actionPerformed(); } }); formatRadioButtons.add(hexaMenuItem); numericFormatSubMenu.add(hexaMenuItem); binMenuItem = new JRadioButtonMenuItem("Binary"); binMenuItem.setMnemonic(KeyEvent.VK_B); binMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { binMenuItem_actionPerformed(); } }); formatRadioButtons.add(binMenuItem); numericFormatSubMenu.add(binMenuItem); viewMenu.addSeparator(); singleStepMenuItem = new JMenuItem("Single Step", KeyEvent.VK_S); singleStepMenuItem.setAccelerator(KeyStroke.getKeyStroke("F11")); singleStepMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { singleStepMenuItem_actionPerformed(); } }); runMenu.add(singleStepMenuItem); ffwdMenuItem = new JMenuItem("Run", KeyEvent.VK_F); ffwdMenuItem.setAccelerator(KeyStroke.getKeyStroke("F5")); ffwdMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ffwdMenuItem_actionPerformed(); } }); runMenu.add(ffwdMenuItem); stopMenuItem = new JMenuItem("Stop", KeyEvent.VK_T); stopMenuItem.setAccelerator(KeyStroke.getKeyStroke("shift F5")); stopMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { stopMenuItem_actionPerformed(); } }); runMenu.add(stopMenuItem); rewindMenuItem = new JMenuItem("Reset", KeyEvent.VK_R); rewindMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { rewindMenuItem_actionPerformed(); } }); runMenu.add(rewindMenuItem); runMenu.addSeparator(); breakpointsMenuItem = new JMenuItem("Breakpoints", KeyEvent.VK_B); breakpointsMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { breakpointsMenuItem_actionPerformed(); } }); runMenu.add(breakpointsMenuItem); profilerMenuItem = new JMenuItem("Profiler", KeyEvent.VK_I); profilerMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showProfiler(); } }); profilerMenuItem.setEnabled(false); runMenu.add(profilerMenuItem); usageMenuItem = new JMenuItem("Usage", KeyEvent.VK_U); usageMenuItem.setAccelerator(KeyStroke.getKeyStroke("F1")); usageMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { usageMenuItem_actionPerformed(); } }); helpMenu.add(usageMenuItem); aboutMenuItem = new JMenuItem("About ...", KeyEvent.VK_A); aboutMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { aboutMenuItem_actionPerformed(); } }); helpMenu.add(aboutMenuItem); }
/** Enables the animation mode buttons. */ public void enableAnimationModes() { animationCombo.setEnabled(true); partAnimMenuItem.setEnabled(true); fullAnimMenuItem.setEnabled(true); noAnimMenuItem.setEnabled(true); }
/** Disables the animation mode buttons. */ public void disableAnimationModes() { animationCombo.setEnabled(false); partAnimMenuItem.setEnabled(false); fullAnimMenuItem.setEnabled(false); noAnimMenuItem.setEnabled(false); }
// --------------------ActionEvent------------------------------------------------------------- public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof PuzzelHAButton) { if (firstClick) { firstClick = false; lastIcon = buttons[0][0].getIcon(); buttons[0][0].setIcon(null); for (int i = 0; i < 10000; i++) { int zufallY = (int) ((Math.random() * YY) + 0); int zufallX = (int) ((Math.random() * XX) + 0); switchButton(zufallY, zufallX); } while (lastButtonX != 0) switchButton(lastButtonY, lastButtonX - 1); while (lastButtonY != 0) switchButton(lastButtonY - 1, lastButtonX); } else { PuzzelHAButton tmp = (PuzzelHAButton) e.getSource(); int posY = tmp.getPosY(); int posX = tmp.getPosX(); switchButton(posY, posX); if (isDone()) { buttons[0][0].setIcon(lastIcon); firstClick = true; } } } else if (e.getSource() instanceof JMenuItem) { if (e.getActionCommand().equals("reset")) { neu(XX, YY); } if (e.getActionCommand().equals("?")) { JFrame inf = new JFrame("Info"); inf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); JLabel jl = new JLabel(); jl.setIcon(new ImageIcon("modify.jpg")); inf.add(jl, BorderLayout.CENTER); inf.setLocationRelativeTo(window); inf.pack(); inf.setResizable(false); inf.setVisible(true); } if (e.getSource() instanceof JRadioButtonMenuItem) { switch (e.getActionCommand()) { case "g1": neu(2, 3); break; case "g2": neu(4, 3); break; case "g3": neu(6, 5); break; case "g4": neu(8, 7); break; case "b": JRadioButtonMenuItem temp = (JRadioButtonMenuItem) e.getSource(); bildNr = temp.getName(); neu(XX, YY); break; default: System.out.println("Test"); break; } } } }
/** Creates new form. */ public PopupMenuTest() { initComponents(); ActionListener a = new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println(evt); } }; JPopupMenu pm = new JPopupMenu(); JMenu m; JMenuItem mi; JCheckBoxMenuItem cbmi; JRadioButtonMenuItem crmi; mi = new JMenuItem("Menu Item 1"); mi.addActionListener(a); pm.add(mi); mi = new JMenuItem("Menu Item 2"); mi.addActionListener(a); pm.add(mi); mi = new JMenuItem("Menu Item 3"); mi.addActionListener(a); pm.add(mi); m = new JMenu("Menu 1"); mi = new JMenuItem("Menu Item 1.1"); mi.addActionListener(a); m.add(mi); mi = new JMenuItem("Menu Item 1.2"); mi.addActionListener(a); m.add(mi); pm.add(m); pm.addSeparator(); cbmi = new JCheckBoxMenuItem("Checkbox Menu Item"); pm.add(cbmi); pm.addSeparator(); ButtonGroup group = new ButtonGroup(); crmi = new JRadioButtonMenuItem("Radio Menu Item 1"); crmi.setSelected(true); group.add(crmi); pm.add(crmi); crmi = new JRadioButtonMenuItem("Radio Menu Item 2"); group.add(crmi); pm.add(crmi); popupMenu = pm; /* //setComponentPopupMenu(pm); //jLabel1.setComponentPopupMenu(pm); JButton button = new JButton("Hi"); // button.setComponentPopupMenu(pm); button.setInheritsPopupMenu(true); add(button, BorderLayout.SOUTH); */ MouseAdapter popper1 = new MouseAdapter() { public void mousePressed(MouseEvent evt) { if (evt.isPopupTrigger()) { showPopupMenu(evt); } } public void mouseReleased(MouseEvent evt) { if (evt.isPopupTrigger()) { showPopupMenu(evt); } } protected void showPopupMenu(MouseEvent evt) { popupMenu.show((Component) evt.getSource(), evt.getX(), evt.getY()); } }; popupLabel1.addMouseListener(popper1); popupField.addMouseListener(popper1); MouseAdapter popper2 = new MouseAdapter() { public void mousePressed(MouseEvent evt) { if (evt.isPopupTrigger()) { showPopupMenu(evt); } } public void mouseReleased(MouseEvent evt) { if (evt.isPopupTrigger()) { showPopupMenu(evt); } } protected void showPopupMenu(MouseEvent evt) { Dimension ps = popupMenu.getPreferredSize(); popupMenu.show(popupLabel2, evt.getX() - ps.width / 2, evt.getY() - ps.height / 2); } }; popupLabel2.addMouseListener(popper2); }
public PuzzelHA() { window = new JFrame("PuzzelHA"); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // window.setSize(800, 600); // -----------------Menü erstellen--------------------------------------- JMenuBar menu = new JMenuBar(); menu.setBorder(new LineBorder(Color.BLACK, 1)); JMenu spiel = new JMenu("Spiel"); JMenuItem reset = new JMenuItem("Reset"); reset.addActionListener(this); reset.setActionCommand("reset"); spiel.add(reset); JMenu ansicht = new JMenu("Ansicht"); JMenu bild = new JMenu("BildNr."); ansicht.add(bild); ButtonGroup bg1 = new ButtonGroup(); for (int j = 1; j <= bilder.size(); j++) { JRadioButtonMenuItem bn = new JRadioButtonMenuItem("" + j); bn.setName("" + j); bn.setActionCommand("b"); bn.addActionListener(this); bg1.add(bn); bild.add(bn); } // --------------RadioButtons für Puzzelgröße---------------------------------- JMenu pg = new JMenu("Puzzelgröße"); ansicht.add(pg); ButtonGroup bg2 = new ButtonGroup(); JRadioButtonMenuItem pgb1 = new JRadioButtonMenuItem("2x3"); pgb1.setActionCommand("g1"); pgb1.addActionListener(this); bg2.add(pgb1); pg.add(pgb1); for (int i = 2; i <= 4; i++) { JRadioButtonMenuItem pgb = new JRadioButtonMenuItem("" + (i * 2) + "x" + (i * 2 - 1)); pgb.setActionCommand("g" + i); pgb.addActionListener(this); bg2.add(pgb); pg.add(pgb); } JMenu help = new JMenu("?"); JMenuItem info = new JMenuItem("Info"); info.addActionListener(this); info.setActionCommand("?"); help.add(info); menu.add(spiel); menu.add(ansicht); menu.add(help); window.add(menu); window.setJMenuBar(menu); // ---------------- Menü END------------------------------------- baueButton(); window.setResizable(false); window.setLocationRelativeTo(null); window.pack(); window.setVisible(true); }
/** Creates new instance. */ public ODGDrawingPanel() { ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); initComponents(); undoManager = new UndoRedoManager(); editor = new DefaultDrawingEditor(); editor.add(view); addCreationButtonsTo(creationToolbar, editor); ButtonFactory.addAttributesButtonsTo(attributesToolbar, editor); JPopupButton pb = new JPopupButton(); pb.setItemFont(UIManager.getFont("MenuItem.font")); labels.configureToolBarButton(pb, "actions"); pb.add(new DuplicateAction()); pb.addSeparator(); pb.add(new GroupAction(editor)); pb.add(new UngroupAction(editor)); pb.addSeparator(); pb.add(new BringToFrontAction(editor)); pb.add(new SendToBackAction(editor)); pb.addSeparator(); pb.add(new CutAction()); pb.add(new CopyAction()); pb.add(new PasteAction()); pb.add(new SelectAllAction()); pb.add(new SelectSameAction(editor)); pb.addSeparator(); pb.add(undoManager.getUndoAction()); pb.add(undoManager.getRedoAction()); // FIXME - We need a toggle grid action // pb.addSeparator(); // pb.add(new ToggleGridAction(editor)); JMenu m = new JMenu(labels.getString("view.zoomFactor.text")); JRadioButtonMenuItem rbmi; ButtonGroup group = new ButtonGroup(); m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 0.1, null))); group.add(rbmi); m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 0.25, null))); group.add(rbmi); m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 0.5, null))); group.add(rbmi); m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 0.75, null))); group.add(rbmi); m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 1.0, null))); rbmi.setSelected(true); group.add(rbmi); m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 1.25, null))); group.add(rbmi); m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 1.5, null))); group.add(rbmi); m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 2, null))); group.add(rbmi); m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 3, null))); group.add(rbmi); m.add(rbmi = new JRadioButtonMenuItem(new ZoomAction(editor, 4, null))); group.add(rbmi); pb.add(m); pb.setFocusable(false); creationToolbar.addSeparator(); creationToolbar.add(pb); DefaultDrawing drawing = new DefaultDrawing(); view.setDrawing(drawing); drawing.addUndoableEditListener(undoManager); }
private void setUpMenuBar() { // Set Up Menu Bar JMenuBar menu = new JMenuBar(); // Game Menu JMenu gameMenu = new JMenu("Game"); menu.add(gameMenu); JMenuItem newRandom = new JMenuItem("New Game"); gameMenu.add(newRandom); newRandom.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); newRandom.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { newGame(); } }); gameMenu.addSeparator(); ButtonGroup bg = new ButtonGroup(); JRadioButtonMenuItem size4 = new JRadioButtonMenuItem("4x4 board"); size4.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { myBoardSize = 4; } }); size4.setSelected(true); bg.add(size4); gameMenu.add(size4); JRadioButtonMenuItem size5 = new JRadioButtonMenuItem("5x5 board"); size5.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { myBoardSize = 5; } }); bg.add(size5); gameMenu.add(size5); gameMenu.addSeparator(); JMenuItem gameTime = new JMenuItem("Time (secs)"); gameMenu.add(gameTime); gameTime.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String secs = JOptionPane.showInputDialog(BoggleGUI.this, "time in seconds"); try { int len = Integer.parseInt(secs); myGameLength = len; myProgress.setMaximum(myGameLength); } catch (NumberFormatException e1) { if (secs != null) { showError(secs + " not valid integer value"); } } } }); gameMenu.addSeparator(); JMenuItem quitGame = new JMenuItem("Quit"); gameMenu.add(quitGame); quitGame.setMnemonic('Q'); quitGame.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); // Help menu JMenu helpMenu = new JMenu("Help"); menu.add(helpMenu); helpMenu.setMnemonic(KeyEvent.VK_H); JMenuItem aboutGame = new JMenuItem("About..."); helpMenu.add(aboutGame); aboutGame.setMnemonic(KeyEvent.VK_A); aboutGame.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog( BoggleGUI.this, "Compsci Boggle, brought to you\n" + "by educators and students\n" + "including, of course, you.", "About Game", JOptionPane.PLAIN_MESSAGE); } }); setJMenuBar(menu); }