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
2
votes
1 answer

How to clear JFrame area by clicking another sub menu of JMenuBar in java Swing?

the code is there for clearing the Frame area by clicking the sub menu(sub_menu_purchase and sub_menu_sale) of main menu. public void clear() { Graphics g = getGraphics(); Dimension d = getSize(); …
Manoj Gupta
  • 298
  • 1
  • 4
  • 20
2
votes
2 answers

Why doesn't MouseListener work?

Here is my main class: import javax.swing.*; public class WordProcessor { public static void main(String[] args) { MainFrame frame = new MainFrame("Word Processor", 10000, 10000); } } and i have two other…
user2465510
  • 99
  • 10
2
votes
0 answers

How to remove or disable a menu item from a JPopupMenu?

I have a JPopupMenu and I want to disable or remove, if possible, a menu item every time an action happens. So I tried this, and though the removeCommentAction object is added in the position 4 of the menu, the menu item in position 4 is not…
PetMarion
  • 147
  • 3
  • 14
2
votes
2 answers

Height of JMenuBar, JMenu and JMenuItem

Is it possible to set height of JMenuBar, JMenu and JMenuItem using UIManager once for all menus? I am currently using: setPreferredSize(new Dimension(100, 25)); But I feel it's not the best way.
Edward Ruchevits
  • 6,411
  • 12
  • 51
  • 86
2
votes
2 answers

JMenuItem - how to figure out if action was invoked by accelerator?

So I have to create a simple GUI in Swing for my Java class and I've stumbled upon this minor cosmetic issue. I have the following code: JMenuItem mntmQuit = new JMenuItem("Quit"); mntmQuit.addActionListener(new ActionListener() { …
2
votes
3 answers

Adding a JMenu to a JPanel

I need to have a JMenu (the one with the arrow on right which can display JMenuItem) in a JPanel. The problem is that when I do that the JMenu is not activate on mouse rollover... I don't know how to do that and if it's possible.
paranoia25
  • 626
  • 1
  • 5
  • 23
2
votes
1 answer

Change an AbstractAction name

I have a JMenuItem bounded to an Action that I can get using item.getAction(). The action name is set when constructing the Action, e.g. using anonymous new AbstractAction(String text, ...). The text field is set according to a ResourceBundle and…
remi
  • 3,914
  • 1
  • 19
  • 37
2
votes
1 answer

Java Swing JSeparator in Menu incorrectly placed

I have a problem when i want insert a separator with JSeparator for Java Swing application. In point of fact, I have this problem just when i run my program on Mac, i haven't it on windows or linux. The separator is incorrectly placed, the text is…
Tof
  • 301
  • 5
  • 17
2
votes
3 answers

How do I call dispose() on a JMenuItem?

I'm trying to write code so that when a user clicks the 'File' tab and selects 'Exit', it exits the whole window I've built. I am trying to use the dispose(); method, but it gives me the error "The method dispose() is undefined for the type new…
Lion
  • 117
  • 2
  • 5
2
votes
1 answer

Creating shortcuts for JMenuItems in JPopupMenu

I need shortcuts for the JMenuItems in JPopupMenu. In the code given below Shortcuts are not working. import java.awt.event.*; import javax.swing.*; import static java.awt.event.InputEvent.CTRL_DOWN_MASK; public class test3 implements…
Roronoa
  • 281
  • 3
  • 10
2
votes
1 answer

ActionListener in InternalFrame that opens another InternalFrame

I'm currently writing a Desktop-Application with Swing that consists of a MainFrame in which several InternalFrames will be running. I want to write the InternalFrames in separate classes for each to avoid having one huge MainFrame-class. Now my…
2
votes
2 answers

How to make JMenuBar activate menu without popping it up?

I try to make my JMenuBar to activate first JMenu on Alt KeyEvent, but without opening popup, so that one could open popup with arrows keystrokes later. Just like it is done in NetBeans, Mozilla, any other program window. Here is the code that works…
yggdraa
  • 2,002
  • 20
  • 23
2
votes
2 answers

Create an object name from a String

I asked this question a few hours ago, but I think I didn't explain myself well. Here is my code: for (a = 1; a < 14; a++) { JMenuItem "jmenu"+a = new JMenuItem(String.valueOf(a)); "jmenu"+a.addActionListener(new ActionListener() { …
Esteru
  • 177
  • 1
  • 7
2
votes
2 answers

Creating JMenuitem's in a for loop

Greeting, I'm trying to do this: public float a=0; for(a=1 ; a<100;a++){ String fuent="font"+String.valueOf((int)a); JMenuItem fuent=new JMenuItem(String.valueOf(a)); fuent.addActionListener(new ActionListener(){ public void…
Esteru
  • 177
  • 1
  • 7
2
votes
2 answers

Handle JPopupMenu closed

I want to highlight some elements on screen, when one JMenuItem in PopupMenu ist selected(mouse over). So i use MouseListener on my JMenuItem with @Override public void mouseEntered(MouseEvent e) { highlightOn(); …
AvrDragon
  • 7,139
  • 4
  • 27
  • 42