Windows ispopuptrigger
In response to the mouseClicked, mouseEntered, mouseExited, mousePressed, and mouseReleased notifications, call the isPopupTrigger on the MouseEvent object to determine if the popup menu was requested. The specific mouse events that cause isPopupTrigger to return true are platform dependent; on Windows, isPopupTrigger returns true when the right mouse button is pressed. If the popup menu is requested, call BackgroundChecker's isInMisspelledWord method to determine if the popup menu was requested over a word highlighted as misspelled.
If the popup menu was requested over a misspelled word, call BackgroundChecker's createPopupMenu method to create a JPopupMenu object populated with items specific to the misspelled word, including suggested replacements and, optionally, Ignore All and Add items. Call JPopupMenu's show method to present the popup menu. The text you want to spell check may not be entered by the user -- it may be read from a disk file or database, or obtained from data structures within your Java application.
Sentry Spellchecker can check words contained in Java Strings interactively or not interactively. The String can contain a single word or an entire book. Sentry will check the spelling of words in the String. If a misspelled word is found, Sentry will pop up a dialog the user can interact with to dispose of the problem. The dialog shows suggested replacements for the misspelled word. If the user makes a correction, the String will be updated automatically.
I've seen this or similar odd popup behavior before in Java applications that were originally written on Windows and later run on Mac. It us usually the result of using the isPopupTrigger method incorrectly or not at all. Scanning the iReport source code I don't detect the use of isPopupTrigger method. Essentially one uses the isPopupTrigger method in both the mousePressed and mouseReleased event handlers to determine whether a mouse press or release really represents a popup invocation.
On a given platform it will be either press or release but not both. One more possibly not relevant point. Recall that Java treats pressing the right button in Windows as equivalent to holding down the Meta key while pressing the left mouse button. Ideally MouseAdapter would spare me the question by offering an overridable popupRequest MouseEvent e , but it doesn't.
So what is the always right, works everywhere on all platforms and always will forever solution? Also, some of the widgets I'm extending may have their own popup menus; I need to suppress those and implement my own. How do I make sure only my own menu is displayed? Read the section from the Swing tutorial on Bringing up a Popup Menu for the basic of using menus and popup menus.
Also note the the example from the tutorial is older. The newer approach for adding a popup menu to a component is to use:. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Collectives on Stack Overflow. Learn more. Asked 1 year, 11 months ago. Active 1 year, 11 months ago. Viewed times. Scott M Scott M 5 5 silver badges 10 10 bronze badges. You need to check mousePressed, mouseReleased, and mouseClicked.
0コメント