Java Code Examples for javax.swing.JMenuItem#getText()

The following examples show how to use javax.swing.JMenuItem#getText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwingSet2.java    From beautyeye with Apache License 2.0 6 votes vote down vote up
/**
 * Stores the current L&F, and calls updateLookAndFeel, below.
 *
 * @param laf the new look and feel
 */
public void setLookAndFeel(String laf) {
	if(currentLookAndFeel != laf) {
		currentLookAndFeel = laf;
		/* The recommended way of synchronizing state between multiple
		 * controls that represent the same command is to use Actions.
		 * The code below is a workaround and will be replaced in future
		 * version of SwingSet2 demo.
		 */
		String lafName = null;
		if(laf == metal) lafName = getString("LafMenu.java_label");
		if(laf == gtk) lafName = getString("LafMenu.gtk_label");
		if(laf == windows) lafName = getString("LafMenu.windows_label");
		
		themesMenu.setEnabled(laf == metal);
		updateLookAndFeel();
		for(int i=0;i<lafMenu.getItemCount();i++) {
			JMenuItem item = lafMenu.getItem(i);
			if(item.getText() == lafName) {
				item.setSelected(true);
			} else {
				item.setSelected(false);
			}
		}
	}
}
 
Example 2
Source File: MenuDemo.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    JMenuItem source = (JMenuItem) (e.getSource());
    String s = "Action event detected." + newline + "    Event source: " + source.getText() + " (an instance of "
            + getClassName(source) + ")";
    output.append(s + newline);
    output.setCaretPosition(output.getDocument().getLength());
}
 
Example 3
Source File: MenTest.java    From swing_library with MIT License 5 votes vote down vote up
public void itemStateChanged(ItemEvent e) {
    JMenuItem source = (JMenuItem)(e.getSource());
    String s = "Menu Item source: " + source.getText()
               + " (an instance of " + getClassName(source) + ")"
               + "\n"
               + "    State of check Box: "
               + ((e.getStateChange() == ItemEvent.SELECTED) ?
                 "selected":"unselected");
    jtAreaOutput.append(s + "\n");
    jtAreaOutput.setCaretPosition(jtAreaOutput.getDocument().getLength());
}
 
Example 4
Source File: MenTest.java    From swing_library with MIT License 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    JMenuItem source = (JMenuItem)(e.getSource());
    String s = "Menu Item source: " + source.getText()
               + " (an instance of " + getClassName(source) + ")";
    jtAreaOutput.append(s + "\n");
    jtAreaOutput.setCaretPosition(jtAreaOutput.getDocument().getLength());
}
 
Example 5
Source File: VizDesktop.java    From ontopia with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent ev) {
  JMenuItem source = (JMenuItem) ev.getSource();
  File f = new File(source.getText());
  try {
    loadTopicMap(f);
  } catch (Exception e) {
    // FIXME: Do we ever want this dialog? It was removed to fix bug
    // #2087, but are there any negative side effects?
    // Presumably, this error message always co-occurs with the error
    // message on (currently) line 546 in VizController (SwingWorker worker)
    //! ErrorDialog.showError(vPanel, Messages
    //!    .getString("Viz.TMLoadError"), e);
  }
}
 
Example 6
Source File: FreeColMenuTest.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void itemStateChanged(ItemEvent e) {
    JMenuItem source = (JMenuItem)(e.getSource());
    String s = "Item event detected."
               + newline
               + "    Event source: " + source.getText()
               + " (an instance of " + getClassName(source) + ")"
               + newline
               + "    New state: "
               + ((e.getStateChange() == ItemEvent.SELECTED) ?
                 "selected":"unselected");
    output.append(s + newline);
    output.setCaretPosition(output.getDocument().getLength());
}
 
Example 7
Source File: FreeColMenuTest.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent ae) {
    JMenuItem source = (JMenuItem)ae.getSource();
    String s = "Action event detected."
               + newline
               + "    Event source: " + source.getText()
               + " (an instance of " + getClassName(source) + ")";
    output.append(s + newline);
    output.setCaretPosition(output.getDocument().getLength());
}
 
Example 8
Source File: QueryBuilderInternalFrame.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 
 * ActionListener interface implementation
 * This would presumably handle menu selections, but none of them actually
 * do anything now.
 */
public void actionPerformed(ActionEvent e) {
    if ( DEBUG ) {
        JMenuItem source = (JMenuItem)(e.getSource());
        String s = "Action event detected." // NOI18N
        + "\n" // NOI18N
        + "    Event source: " + source.getText() // NOI18N
        + " (an instance of " + getClassName(source) + ")"; // NOI18N
        System.out.println (s + "\n"); // NOI18N
    }
}
 
Example 9
Source File: PopupMenuDemo.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void itemStateChanged(ItemEvent e) {
    JMenuItem source = (JMenuItem) (e.getSource());
    String s = "Item event detected." + newline + "    Event source: " + source.getText() + " (an instance of "
            + getClassName(source) + ")" + newline + "    New state: "
            + ((e.getStateChange() == ItemEvent.SELECTED) ? "selected" : "unselected");
    output.append(s + newline);
    output.setCaretPosition(output.getDocument().getLength());
}
 
Example 10
Source File: PopupMenuDemo.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    JMenuItem source = (JMenuItem) (e.getSource());
    String s = "Action event detected." + newline + "    Event source: " + source.getText() + " (an instance of "
            + getClassName(source) + ")";
    output.append(s + newline);
    output.setCaretPosition(output.getDocument().getLength());
}
 
Example 11
Source File: PopupMenuDemoX.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void itemStateChanged(ItemEvent e) {
    JMenuItem source = (JMenuItem) (e.getSource());
    String s = "Item event detected." + newline + "    Event source: " + source.getText() + " (an instance of "
            + getClassName(source) + ")" + newline + "    New state: "
            + ((e.getStateChange() == ItemEvent.SELECTED) ? "selected" : "unselected");
    output.append(s + newline);
    output.setCaretPosition(output.getDocument().getLength());
}
 
Example 12
Source File: PopupMenuDemoX.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    JMenuItem source = (JMenuItem) (e.getSource());
    String s = "Action event detected." + newline + "    Event source: " + source.getText() + " (an instance of "
            + getClassName(source) + ")";
    output.append(s + newline);
    output.setCaretPosition(output.getDocument().getLength());
}
 
Example 13
Source File: MenuSelectionManagerDemo.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void itemStateChanged(ItemEvent e) {
    JMenuItem source = (JMenuItem) (e.getSource());
    String s = "Item event detected." + newline + "    Event source: " + source.getText() + " (an instance of "
            + getClassName(source) + ")" + newline + "    New state: "
            + ((e.getStateChange() == ItemEvent.SELECTED) ? "selected" : "unselected");
    output.append(s + newline);
    output.setCaretPosition(output.getDocument().getLength());
}
 
Example 14
Source File: MenuSelectionManagerDemo.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    JMenuItem source = (JMenuItem) (e.getSource());
    String s = "Action event detected." + newline + "    Event source: " + source.getText() + " (an instance of "
            + getClassName(source) + ")";
    output.append(s + newline);
    output.setCaretPosition(output.getDocument().getLength());
}
 
Example 15
Source File: MenuDemo.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void itemStateChanged(ItemEvent e) {
    JMenuItem source = (JMenuItem) (e.getSource());
    String s = "Item event detected." + newline + "    Event source: " + source.getText() + " (an instance of "
            + getClassName(source) + ")" + newline + "    New state: "
            + ((e.getStateChange() == ItemEvent.SELECTED) ? "selected" : "unselected");
    output.append(s + newline);
    output.setCaretPosition(output.getDocument().getLength());
}
 
Example 16
Source File: JMenuItemJavaElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static String getItemText(JMenuItem current) {
    String text = current.getText();
    if (text == null || "".equals(text)) {
        return getTextFromIcon(current);
    }
    return text;
}
 
Example 17
Source File: MenuChecker.java    From netbeans with Apache License 2.0 4 votes vote down vote up
NbMenu(JMenuItem menu, List<NbMenu> submenu) {
    name = menu.getText();//getLabel();
    accelerator = (menu.getAccelerator() == null) ? null : menu.getAccelerator().toString();
    mnemo = menu.getMnemonic();
    this.submenu = submenu;
}
 
Example 18
Source File: SeaGlassMenuItemUI.java    From seaglass with Apache License 2.0 4 votes vote down vote up
static Dimension getPreferredMenuItemSize(SeaGlassContext context, SeaGlassContext accContext, boolean useCheckAndArrow, JComponent c,
    Icon checkIcon, Icon arrowIcon, int defaultTextIconGap, String acceleratorDelimiter) {
    JMenuItem b = (JMenuItem) c;
    Icon icon = (Icon) b.getIcon();
    String text = b.getText();
    KeyStroke accelerator = b.getAccelerator();
    String acceleratorText = "";

    if (accelerator != null) {
        int modifiers = accelerator.getModifiers();
        if (modifiers > 0) {
            acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
            acceleratorText += acceleratorDelimiter;
        }
        int keyCode = accelerator.getKeyCode();
        if (keyCode != 0) {
            acceleratorText += KeyEvent.getKeyText(keyCode);
        } else {
            acceleratorText += accelerator.getKeyChar();
        }
    }

    Font font = context.getStyle().getFont(context);
    FontMetrics fm = b.getFontMetrics(font);
    FontMetrics fmAccel = b.getFontMetrics(accContext.getStyle().getFont(accContext));

    resetRects();

    layoutMenuItem(context, fm, accContext, text, fmAccel, acceleratorText, icon, checkIcon, arrowIcon, b.getVerticalAlignment(), b
        .getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect,
        acceleratorRect, checkIconRect, arrowIconRect, text == null ? 0 : defaultTextIconGap, defaultTextIconGap, useCheckAndArrow);
    // find the union of the icon and text rects
    r.setBounds(textRect);
    r = SwingUtilities.computeUnion(iconRect.x, iconRect.y, iconRect.width, iconRect.height, r);
    // To make the accelerator texts appear in a column,
    // find the widest MenuItem text and the widest accelerator text.

    // Get the parent, which stores the information.
    Container parent = b.getParent();

    if (parent instanceof JPopupMenu) {
        SeaGlassPopupMenuUI popupUI = (SeaGlassPopupMenuUI) SeaGlassLookAndFeel.getUIOfType(((JPopupMenu) parent).getUI(),
            SeaGlassPopupMenuUI.class);

        if (popupUI != null) {
            r.width = popupUI.adjustTextWidth(r.width);

            popupUI.adjustAcceleratorWidth(acceleratorRect.width);

            r.width += popupUI.getMaxAcceleratorWidth();
        }
    } else if (parent != null && !(b instanceof JMenu && ((JMenu) b).isTopLevelMenu())) {
        r.width += acceleratorRect.width;
    }

    if (useCheckAndArrow) {
        // Add in the checkIcon
        r.width += checkIconRect.width;
        r.width += defaultTextIconGap;

        // Add in the arrowIcon
        r.width += defaultTextIconGap;
        r.width += arrowIconRect.width;
    }

    r.width += 2 * defaultTextIconGap;

    Insets insets = b.getInsets();
    if (insets != null) {
        r.width += insets.left + insets.right;
        r.height += insets.top + insets.bottom;
    }

    // if the width is even, bump it up one. This is critical
    // for the focus dash line to draw properly
    if (r.width % 2 == 0) {
        r.width++;
    }

    // if the height is even, bump it up one. This is critical
    // for the text to center properly
    if (r.height % 2 == 0) {
        r.height++;
    }
    return r.getSize();
}