Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8347161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:16:34+00:00 2026-06-09T07:16:34+00:00

I have tray icon and I’ve attached a menu to it so that when

  • 0

I have tray icon and I’ve attached a menu to it so that when the user right clicks on it, it pops up.

At point in my application I’d like to disable the content menu from showing and the re-enable it again later. How I do this? I haven’t been able to find an example and doing mnuPopup.setEnabled(false) doesn’t seem to work.

Here’s the snippet of code that creates the tray icon and attaches the menu to it.

Tray trySysTray = display.getSystemTray();
Menu mnuPopup = new Menu(shell, SWT.POP_UP);
TrayItem itmTrayItem = new TrayItem(trySysTray, SWT.NONE);

itmTrayItem.addListener(SWT.MenuDetect, new Listener() {
    public void handleEvent(Event event) {
        mnuPopup.setVisible(true);
    }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:16:38+00:00Added an answer on June 9, 2026 at 7:16 am

    The following should do the job:

    public class MiniExample {
        // the boolean to decide if menu is shown
        private static boolean showMenu = true;
    
        public static void main(String[] args) {
            Display display = Display.getDefault();
            final Shell shell = new Shell(display);
            shell.setLayout(new FillLayout());
    
            Tray tray = display.getSystemTray();
            final TrayItem item = new TrayItem(tray, SWT.NONE);
    
            // INPUT A REAL IMAGE HERE!
            item.setImage(SOME_IMAGE);
    
            item.addMenuDetectListener(new MenuDetectListener() {
    
                @Override
                public void menuDetected(MenuDetectEvent event) {
                // if menu shall not be shown, tell it to the event
                    if(!showMenu)
                    {
                        event.doit = false;
                        return;
                    }
    
                // else create the menu
                    Menu menu = new Menu(shell, SWT.POP_UP);
                    MenuItem menuitem = new MenuItem(menu, SWT.PUSH);
                    menuitem.setText("Do Something");
                    menuitem.addListener(SWT.Selection, new Listener() {
                        public void handleEvent(Event e) {
                            System.out.println("Do something!");
                        }
                    });
    
                    menu.setVisible(true);
                    while (!menu.isDisposed() && menu.isVisible()) {
                        if (!shell.getDisplay().readAndDispatch())
                            shell.getDisplay().sleep();
                    }
    
                // remember to dispose it !!
                    menu.dispose();
                }
            });
    
            Button button = new Button(shell, SWT.PUSH);
            button.setText("Button");
            button.addSelectionListener(new SelectionListener() {
    
                @Override
                public void widgetSelected(SelectionEvent arg0) {
                    // button decides if menu is shown or not
                    showMenu = !showMenu;
                }
    
                @Override
                public void widgetDefaultSelected(SelectionEvent arg0) {
    
                }
            });
    
            shell.pack();
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Qt application with a system tray icon and a menu that
I have a java application which has a tray icon in the top menu
I have implemented tray icon menu for QT application. But the tray icon menu
I am trying to create an application that will have a tray icon only,
I have a Java app that has an icon in the system tray. How
I'm using NotifyIcon (System tray icon) in my WinForms application. I also have a
I have a program which creates DialogBox window when user clicks the menu item
I have an AIR application with a system tray icon. When clicked it shows
I have a application that is based out of the system tray. I have
I'm writing an application in C++ that runs as a system tray icon. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.