Results 1 to 4 of 4
  1. #1
    Valhallon is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Question Canīt change selected/pressed Icon of a JMenu

    Is it possible to make such thing? Iīve made it easily before with JButton, but with JMenuīs and JMenuItemīs I just canīt.

    Code:

    JMenu file = new JMenu();//Menu "Start"
    file.setIcon(StartIcon);//Only shows this Icon when selected/pressed
    file.setPressedIcon(StartIconSelect);

  2. #2
    devunion is offline Member
    Join Date
    Jun 2008
    Posts
    56
    Rep Power
    0

    Default

    No, there is no such method. You can use file.addMouseListener(...);. In this listener you can change your icon.
    Try Controls4J - Advanced Swing Components.

  3. #3
    Valhallon is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    Worked really fine, thx a lot!

    Btw, how can I mark this as solved? Lol sorry but im a newb in here

  4. #4
    Mad Matt is offline Member
    Join Date
    Jul 2011
    Posts
    1
    Rep Power
    0

    Default

    I realize this reply comes two years later, but I was trying to solve the same problem.

    Try this instead. Uses a MenuListener instead of a MouseListener:

    Java Code:
    JMenu menu = new JMenu();
    menu.setIcon(normalIcon);
    menu.addMenuListener(new MenuListener() {
        public void menuSelected(MenuEvent e) {
            ((JMenu) e.getSource()).setIcon(selectedIcon);
        }
    
        public void menuDeselected(MenuEvent e) {
            ((JMenu) e.getSource()).setIcon(normalIcon);
        }
    
        public void menuCanceled(MenuEvent e) {
            ((JMenu) e.getSource()).setIcon(normalIcon);
        }
    });
    Last edited by Mad Matt; 07-08-2011 at 11:23 PM.

Similar Threads

  1. How to change Window Icon
    By sharafat in forum AWT / Swing
    Replies: 7
    Last Post: 01-15-2010, 01:37 AM
  2. get key pressed
    By prashant in forum Networking
    Replies: 1
    Last Post: 03-26-2009, 10:10 PM
  3. JMenu to JPopupMenu
    By carderne in forum New To Java
    Replies: 0
    Last Post: 02-28-2009, 07:07 PM
  4. when muse pressed the background change
    By pcman in forum Java Applets
    Replies: 1
    Last Post: 03-18-2008, 12:51 AM
  5. JMenu and JRadioButtonMenuItem
    By doron70 in forum AWT / Swing
    Replies: 3
    Last Post: 07-18-2007, 07:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •