Questions tagged [jmenuitem]

JMenuItem is an implementation of an item in a menu. A menu item is essentially a button sitting in a list. When the user selects the "button", the action associated with the menu item is performed.

JMenuItem is an implementation of an item in a menu. A menu item is essentially a button sitting in a list. When the user selects the "button", the action associated with the menu item is performed. For more info, see this link.

342 questions
3
votes
1 answer

JMenuItem accelerator not working when menu bar is hidden

This question is a follow-up to this question. I have a JMenuBar whose behavior is like the menu bars in Firefox and iTunes. That is, the menu bar is initially hidden, but when you press Alt, the menu bar appears. The answer to the other question…
ryvantage
  • 13,064
  • 15
  • 63
  • 112
3
votes
6 answers

JMenuItem.setSelected() does not alter appearance of selected item?

I wish to programmatically cause a particular item on a menu to be selected and to display as such so that if Enter is pressed, the corresponding action will be performed. Ubnfortunately I find that neither JMenuItem.setSelected(), nor…
Steve Cohen
  • 4,679
  • 9
  • 51
  • 89
3
votes
1 answer

Tooltip for a JMenuItem

I add a menu to a toolbar like this : JMenuBar menu = new JMenuBar(); JMenu actions = new JMenu("Aktionen"); Icon menuIcon = ImageUtilities.loadImageIcon("pathToIcon", true); actions.setIcon(menuIcon); // Add JMenuItem…
Jannis Alexakis
  • 1,279
  • 4
  • 19
  • 38
3
votes
2 answers

Change text font using menu

I have this code that when user click on one of the fonts "bold or italic..." the text should change. I couldn't add the action listener that will do that: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class question4…
Suma
  • 123
  • 1
  • 4
  • 11
3
votes
3 answers

How to determine if a menu item is clicked

as the title states, i need to know how to determine if a menu item was clicked or not, then run the function associated. for instance i have a JMenu with a JMenuItem "exit", which when clicked should run a close form method. import…
7c00h
  • 91
  • 1
  • 10
3
votes
0 answers

JMenuItem text and accelerator alignment in right to left orientation

I'm using right to left menus in a Java application. I used this on all JMenuBar,JMenu & JMenuItem elements to make them right to left: …
Ariyan
  • 14,760
  • 31
  • 112
  • 175
3
votes
3 answers

Java menu item enabling within event listener

Hello im trying to enable my JMenuItem from within an event listener but it seems to be out of scope. im new to java so how would i properly go about this. the said event listener will change to a new view and enable the disabled menu items. …
Daniel Del Core
  • 3,071
  • 13
  • 38
  • 52
3
votes
2 answers

JMenuItem: how to set an Accelerators with 3 keys?

Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MenuActions extends JFrame { private JMenuBar jmb; private JMenu file; private JMenuItem open; public…
PeakGen
  • 21,894
  • 86
  • 261
  • 463
2
votes
2 answers

Actionlistener on a JMenu not working

I have a JMenu and I added a Actionlistener to to it but the Action listener doesn't do anything. I am trying to make the mnExit menu exit the program (System.exit(0)), but the Actionlistener doesn't do anything. Can anyone tell what I did wrong…
user1272067
  • 33
  • 1
  • 4
2
votes
2 answers

Add functionality to a menu button in java

I am new to Java and I was wondering how to add functionality to menu item? What I would like it to do, is to set two values to 0. This is the code I have currently: JMenuItem clear = new JMenuItem("Clear"); Options.add(clear);
Java noob
  • 23
  • 1
  • 1
  • 3
2
votes
1 answer

Remove all JMenuItem from JMenu

I got the JMenu down except for removing. :D I mean, I can do popup.remove(NUMBER) but that can cause NPE errors. So, is there a way to remove all JMenuItems from JMenu? Here's my update checkPopup() if anyone's interested: private void…
test
  • 17,706
  • 64
  • 171
  • 244
2
votes
1 answer

JMenuItem reuse

Here is the minimal working application : import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; import…
Bogdan A.
  • 65
  • 1
  • 8
2
votes
4 answers

JAVA: how to use listeners on JMenuItem and Jbutton to calculate rates

I'm writing a currency converter but I'm having a bit of trouble caculating the exchange rate for each currency. basically I want the user to select a currecy first then enter an amount and press "go" button to calculate the rate. but i'm having…
Maxi90
  • 33
  • 1
  • 6
2
votes
1 answer

Get JMenu from JMenuItem with JPopupMenu

I would like to get the name of the JMenu when I click on my JMenuItem with a JPopupMenu. I put an ActionListener named "menuContextuelListener" on each JMenuItem: ActionListener menuContextuelListener = new ActionListener() { public void…
Fred
  • 169
  • 1
  • 3
  • 19
2
votes
1 answer

JLabel with icon in JPopupMenu doesn't follow other JMenuItem alignment

I need to add a label at the top of a JPopupMenu that contains other JMenuItems in it. So far, so good. The problem happens because my label has an icon on its left side, just like a "normal" JMenuItem, but the other items won't follow the labels…