JMenuItem « Menu « Java Swing Q&A





1. JMenuItem setMinimumSize doesn't work    stackoverflow.com

I try to set a minimum width for my menu items, but it doesn't seem to work. Here is my function, which creates the items:

 private JMenuItem newItem(String text, String iconPath) ...

2. JMenuItem.getRootPane() workaround?    stackoverflow.com

It seems to be well-known there is a bug when using JMenuItem.getRootPane(). I read the bug description but i cannot figure out a workaround. Do you know work-around code for this ...

3. Additional information added to JMenuItem    stackoverflow.com

I'm developing a java application and I create a dynamic JMenu by hand (depending on the input data). I add the same action for each menu item of the menu. The ...

4. JMenu and JMenuItems have thin orange border that I cannot change    stackoverflow.com

I have been using the UIManager to change the coloring scheme on my GUI. For example I use this for JMenuItems:

UIManager.put("MenuItem.foreground", new ColorUIResource(255, 255, 255));
UIManager.put("MenuItem.background", new ColorUIResource(51, 51, 51));
UIManager.put("MenuItem.selectionBackground", new ColorUIResource(232, ...

5. Remove from JMenuItem    stackoverflow.com

OK so I finally got the JListMenu thing down with thanks to you guys. However, now I'm trying to make it so SPECIFIC items have SPECIFIC commands. So, like Item 1 ...

6. An efficient way of adding JMenuItems    stackoverflow.com

OK so before my INV program was to REMOVE menu items but then I was all like.. that's too much. So what if I were to ADD menu items for specific ...

7. Remove all JMenuItem from JMenu    stackoverflow.com

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 ...

8. JMenuItem displays weird name    stackoverflow.com

I got my inv finally working! :D But, you know... now... it's dumb. I want it to say "Use Item 1" or whatever when I Right-click so I do this:

  ...

9. I have an instance of JMenuItem (let's say, TEMP). I want to find out, what is the name of JMenu to which a TEMP is added. How?    stackoverflow.com

I have an instance of JMenuItem (let's say, TEMP). I want to find out, what is the name of JMenu to which a TEMP is added. How should I do it? ...





10. Custom JMenuItem's in Java    stackoverflow.com

Would it be possible to create a custom JMenuItem that contains buttons? For example would it be possible to create a JMenu with an item similar to this: http://imageshack.us/photo/my-images/31/screenshot20110511at202.png/

+----------------------------------------+
| ...

11. can I trigger SimpleButtonAction?    stackoverflow.com

I have a menu bar with many SimpleButtonAction. Some of them need to show if they are pressed or not (for example, the "show grid" button). I have looked for this feature, ...

12. JMenuItem ImageIcon too big    stackoverflow.com

I've encountered a problem. My image is too big so it enlarges the corresponding JMenuItem. I don't want to develop bicycles like

ImageIcon image = new ImageIcon(new ImageIcon("/home/template/img.jpg")
     ...

13. Creating menus for JApplet    stackoverflow.com

I am making a simple game where numbers fall from top to bottom and I have to type the number. (number is erased as I type the number) This is coordinated with a ...

14. JButton inside JMenuItem    stackoverflow.com

I'm trying to build a particular JMenu. I want a JMenuItem with JMenu functionality, I.E. when we click it the item should do something (like opening a dialog). But the JMenuItem should ...

15. Using OSGi to attach JMenuItems to GUI    stackoverflow.com

I have created an application and now I want it to make a plugin ready. I have decided to use Apache Felix and after reading tutorial, I am not sure, whether ...

16. jPopUpMenu Change rollover background    stackoverflow.com

I would like to change the background color of my jMenuItems on a rollover event : enter image description here Now it's blue, i want it white, how can I do ...





17. NodeAction JMenuItem enablement error    forums.netbeans.org

public JPopupMenu getNodePopup(){ final Node node = new MyNode(myLookup); return Utilities.actionsToPopup(node.getActions(false), Lookups.fixed(node, node.getLookup())); }

18. jMenu and jMenuItem HELP!!!    forums.netbeans.org

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) { ...

19. jMenuItem does not show within UI    forums.netbeans.org

20. jMenuItem Not Showing Up In jPopupMenu?    forums.netbeans.org

I have a jPopupMenu that has 2 jMenuItems and separator. For some reason only the first jMenuItem shows up. The other one is there because I can see a rollover effect, but the text is not visible. I have made sure that the menu item has text associated with it. What am I doing wrong? Screenshot attached. Thanks...

21. JMenuItem is not visible, why?    coderanch.com

22. JMenuItem behind other components    coderanch.com

I had that same problem and am not sure how to fix it, since I just scrapped the idea of using a canvas. The reason this happens though is because you are mixing lightweight and heavyweight components. You might try setting the canvas to MIN_VAL so that it lays on the very bottom layer of all your components. ------------------ Happy Coding, ...

23. JMenuItem.setMargin    coderanch.com

Ok, I have started to get this figured out on my own. But there is a problem. Here is my code. import java.awt.*; import java.awt.event.*; import javax.swing.*; class MainMenuBar extends JMenuBar { public MainMenuBar() { ////////////////////////////////////////////////////////////////////////////////////// //Creating the File Menu and it's MenuItems// ////////////////////////////////////////////////////////////////////////////////////// JMenu file = new JMenu("File"); file.setMnemonic(KeyEvent.VK_F); add(file); JMenuItem New = new JMenuItem("New...", new ImageIcon("images//icons//16X16//New.gif")); Insets s = ...

24. Using JMenuItem/Exit not working, about is    coderanch.com

HI: I have a problem where the "about" menuitem functions but Not the "exit" under File. Could someone give me a clue as to what is missing. Not sure whether actionPerform is right for the listeners. There are 4 class files but I am showing just the 2 important ones. thanks, its the final project. capp import java.awt.*; import java.awt.datatransfer.*; import ...

25. what is isArmed() method for in JMenuItem?    coderanch.com

Thanks Dirk for your reply..But I could remember one of my posting perhaps in Java BEgineers where I wanted to point of the poor Java documnetation where it failed to explain the terminology..and the need of small examples for every methods and on this..but someone was not convienced ...but I think this is required... any comments... regards, Arun

27. Aligning JMenuItems    coderanch.com

28. JMenuItem question    coderanch.com

Without seeing more code I'm guessing that you are only creating one instance of the menu items. If this is the case then I believe they should disappear from the first menu when added to the second menu. Maybe try adding a Factory method to create specific instances of the menu items, then you will have the same menu items class ...

29. JMenuItem enable    coderanch.com

Hmmm... Take a look at the example code below and see if it works... import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.*; public class ActionHandler extends JFrame { private JTextArea ta; private JMenuItem mi; private Action action; public ActionHandler() { super( "ActionHandler" ); JMenuBar mb = new JMenuBar(); JMenu menu = new JMenu( "Menu" ); JMenuItem exit = new JMenuItem( "Exit" ...

31. short cut in a JMenuItem    coderanch.com

thanks for the advice. I am already applying actions combine with the command pattern, is very usefull. but I have another problem now, when I run my application on windowsand I place the cursor over the tool bar, I got the tool tips that I seted in the class that I created extending tha AbstractAction class e.g.putValue(SHORT_DESCRIPTION,"Open"), but whe I run ...

34. How to add JMenuItem to my JMenu??    coderanch.com

35. Word wrap in JMenuItem    coderanch.com

36. JPopupMenu - setSelected(JMenuItem)    coderanch.com

38. JMenuItem    coderanch.com

My menu displays the menu items but; the menu items don't respond to clicks. Any clues? Thanks, Gary. package words; import java.awt.event.*; import java.sql.*; import java.util.Locale; import javax.swing.*; public class WordBank implements ActionListener { private UserClass uc; private static Connection con; public WordBank() { JFrame wordBankFrame = new JFrame(); wordBankFrame.setTitle("Word Bank"); wordBankFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); wordBankFrame.setJMenuBar(menuBar); JMenu userMenu = ...

39. Multiple JMenuItem layout    coderanch.com

How many menu items are you talking about, and why won't they fit? Are they cut off at the bottom, or the window isn't wide enough? Have you thought of maybe categorizing the menu items into different menus? Maybe like the file and edit menus, that way it'll show up and maybe make the user interface a little smoother. Let me ...

40. JMenuItem    coderanch.com

42. JMenuItems not triggering keyTyped    coderanch.com

43. JMenuItem centering    coderanch.com

44. JMenuItem width    coderanch.com

45. jmenuitem..unseen    coderanch.com

46. How to use JMenuItem as JMenu?    coderanch.com

48. JMenuItem opens a html file in browser    coderanch.com

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - ...

49. Monospaced font on a JMenuItem    coderanch.com

50. JMenuItem text problem    coderanch.com

51. JMenuItem    coderanch.com

Seems like the JMF window is a native (heavyweight) control, and the menu items are lightweight pure-Java controls. Heavyweight controls will always be shown on top of lightweight controls. That's why it's usually a bad idea to mix AWT (heavyweight) with Swing (mostly lightweight). You could switch to AWT and use its menu items, that should work.

52. jmenuitem..unseen    coderanch.com

53. jmenuitem..unseen    coderanch.com

Hi Maha, You're using a "heavyweight" AWT component like a Canvas or Panel with a "lightweight" Swing JMenuBar. You can't mix Swing and AWT components unless you really know what you're doing. So pick one or the other, and your problem will go away. I'm going to move this to our "Swing/AWT/etc" forum.

54. Sharing JMenuItems    coderanch.com

Ok, I'm stumped. I've searched the 'net but found nothing... probably because no one else in the world has ever encountered this issue. The situation is that I've got a few menu items that I want to share between an edit menu (in a jmenubar) and a popup menu. I build the popup menu first, then add the menu bar. Here's ...

55. JMenuItems    coderanch.com

56. How to set JMenuItem's height ?    coderanch.com

import java.awt.Dimension; import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; public class RunMe extends JFrame { public RunMe() { this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setBounds(10, 10, 800, 600); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("testMenu"); menuBar.add(menu); //menu.getPopupMenu().setMinimumSize(new Dimension(100, 50)); //menu.getPopupMenu().setPreferredSize(new Dimension(100, 50)); //menu.getPopupMenu().setMaximumSize(new Dimension(999, 50)); //menu.getPopupMenu().setLayout(new FlowLayout()); JMenuItem menuItem = new JMenuItem("testMenuItem"); menuItem.setMinimumSize(new Dimension(100, 50)); menuItem.setPreferredSize(new Dimension(100, 50)); //menuItem.setMaximumSize(new Dimension(999, ...

57. JMenuItems    coderanch.com

58. JMenuItem text alignment to CENTER    coderanch.com

String[] menuItems = {"Java Swing Java Swing", "Java Swing Java Swing", "Java Swing
Java Swing"}; JPopupMenu popMenu = new JPopupMenu(""); for (int i = 0; i < menuItems.length; i++) { JMenuItem item = new JMenuItem(menuItems[i]); popMenu.add(item); // I have tried the methods item.setHorizontalTextPosition(JMenuItem.CENTER) and item.setHorizontalAlignment(SwingConstants.CENTER), but it is not align the text to center }

59. JmenuItem    coderanch.com

hi I'm working with netbeans GUI and I have a menu named:file I want this to have sub menus like:new,load,... It seems that I should use jMenuItem,but I can not add events to it(new for example) like usual,because I added mouseClicked event,but when I click :new nothing happens. I would be so thankful if you help me.

60. How to obtain the name of the JMenuItem?    java-forums.org

Hi there! I need some help, how do I get the name of the JMenuItem that the user pressed? I've got some JMenuItems all use the same class "catalogue": iCatalogue = new JMenuItem(subcatalogo); iCatalogue1 = new JMenuItem(subcatalogo); But they are used on different JMenu: mCustomer.add(iCatalogue); mBill.add(iCatalogue1); When I click on Catalogue (the submenu inside of both customer and bill) appears a ...

61. JFrame and JMenuItem    java-forums.org

package test; import java.awt.event.InputEvent; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.Container; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.KeyStroke; public class MenuGUI { private JMenuBar menuBar; /** Constructs the menu bar. */ public MenuGUI(){ menuBar = new JMenuBar(); JMenu consultatie = new JMenu("Consultatie"); menuBar.add(consultatie); JMenuItem nieuweClientItem= new JMenuItem("Nieuwe Clint"); nieuweClientItem.setAccelerator(KeyStroke.getKeyStroke('C', InputEvent.CTRL_DOWN_MASK)); consultatie.add(nieuweClientItem); JMenu boekhouding = new JMenu("Boekhouding"); menuBar.add(boekhouding); nieuweClientItem.addActionListener ( new ActionListener() ...

62. Printing JMenuItems contnets    java-forums.org

63. How to make a transparent JMenuItem    java-forums.org

64. JMenuItem with Java JRE 1.6    java-forums.org

Having an issue with the display of my jMenuItems. They appear correctly with jre 1.4(I know, really old now), but in the later version 1.6 the fomat is stuffed up. On one java application screen I have 4 menus. The first one is a "File" menu with an "Open" menu item that also has a quick key to the right of ...

65. adding dialogbox to Jmenuitem    forums.oracle.com

66. adding a JMenuItem directly to the Top Menu    forums.oracle.com

I want to create the most basic of menu, The Frame has maybe 2 menus attached to it and when i click them i can get them to do something such as Close the window and run a method. Is their any way i can have the top level items that appear on the bar do things without having to go ...

67. JMenuItems    forums.oracle.com

Thats what im trying to use but doesnt seem to be working Yup, I checked that out, the menu item's parent is the popup that is created to display it. I think this problem is better suited to an object oriented approach. You could have a class that extends AbstractAction and takes a constructor parameter that identifies the bookmark. You would ...

68. JMenus and JMenuItems    forums.oracle.com

I wouldn't expect it to show up immediately if it's being added as a result of clicking another item on the same JMenu, only next time you pull that JMenu down. If that doesn't happen, I would try creating a new JMenuItem("hi"), call setVisible(true) on it, and then add it to the JMenu. You shouldn't need to revalidate or repaint anything. ...

69. Calling a native method from JMenuItem and waiting for its reply    forums.oracle.com

Hello, I have a native method that I call when I choose a JMenuItem, which I want everything to wait until I get a reply from the native method. I'm thinking of the Semaphore class in "java.util.concurrent.Semaphore ", but I don't know if this is the correct way to do this. The native method does some stuff with a compiler and ...

70. Help with JMenuItem & EventObject    forums.oracle.com

71. Urgent: problem with dynamic JMenuItem    forums.oracle.com

i have a dynamic JMenu item list that is create with the following codes: ..... for(int ele_counter = 0; ele_counter <= EList.size(); ele_counter++){ menuItem = new JMenuItem(EList.get(ele_counter)); JMI_List.add(menuItem); } ..... EList is the list of arraylist that contain all the title for the JMenuItem. JMI_List is a JMenu. here is a screen shot: http://www.badongo.com/pic/3777072 my questions are: the dynamically generated items ...

72. JMenuItem ???    forums.oracle.com

73. JMenuItems drawn over by JPanel. How to fix?    forums.oracle.com

74. JMenuItem    forums.oracle.com