I'm trying to add a system tray icon, with a right click menu on the icon, for a javafx program.
The answers I've found indicate that the only way to do this is via java.awt.SystemTray
Which is fine, but the popup menu which shows up when I right click the icon in tray, looks very bland. Also, if I hover the mouse over any of the popup menu options, I expect the background color of that option to change, to indicate that I'm selecting it. But this doesn't happen, the menu stays completely static and unchanging until I click an option.
I'm looking for a way that I can listen to the mouseover event on a MenuItem and change its background + foreground color to indicate that it has the focus. But I can't find any methods in the API that let you do this. Is there any other way? Or is there anything else I can do to make the menu seem a bit more responsive?
Related
I have an icon in my application and I made it clickable (When I click the icon, some action is called), but the problem is, you have to be really accurate. On the other hand the menu icon (the 3 dots) has a bigger "range" and when you click little bit outside, it is still working. Is there any way to achieve the same thing at the app icon? Or is there any better way to make a clickable icon in the upper left corner than using app icon?
Add padding to the icon, the more padding you add to it, the more clickable area you ll get!
Try to put a transparent button over your icon. Don't forget to make it unclickable and put enabled to false, so it doesn't intercepts the click intended for the icon.
I have a custom JFrame. On the title bar I have an icon in the top left, a title, and then the standard minimize, maximize, and close buttons on the right.
When I click the icon in the title bar I get the standard options: Restore, Move, Size, Minimize, Maximize, Close.
How can I add my own menu option here? I'd like to add and "Always On Top" option here.
Additionally I'd like to add a button next to the max,min,close buttons on the title bar to allow uses to toggle the "Always On Top" state of the JFrame.
You could create your own customized Components. To do that, create a new class which extends JMenuBar for example and override the methods which fit your needs. Very often, for example, one wants to override paintComponent(Graphics).
That is not what you want, 'though. Customizing the JMenuBar wont work as you expect it to. The "JMenuBar" is another bar below the title bar. I am Mac user, but as far as my knowledge goes, it is not possible to customize the title bar, because that isn't handled by the JVM. The only thing that is modifiable without using native code is the Icon in the top left.
For further information on that, look at this question and the best answer there. This will help you a lot.
Your problem (adding a button at the top for toggling the alwaysOnTop status) is best solved by creating normal instances of a JMenuBar, a JMenu and a JMenuItem.
To then add that MenuBar to your Frame, use JFrame.setJMenuBar(JMenuBar). See also How to use Menus.
I hope this helps!
I have an app with a normal menu i.e. the common old menu that shows up at the bottom of the screen when the menu button is pressed. But it is a problem in some phones where there is no hard menu button.
I want to switch to slider menu with a menu icon on top. Is there an easy way to do this (I mean a way where code change would be minimum) retaining the existing functionality? Or will i have to go about coding the slider menu from scratch?
Any example code of a similar situation would really help.
I have an app with a normal menu i.e. the common old menu that shows up at the bottom of the screen when the menu button is pressed
Normally, that "menu" will appear as the overflow on devices with an action bar that either:
do not have a MENU button, or
run Android 4.4+
But it is a problem in some phones where there is no hard menu button.
Make sure that your app has an action bar.
I want to switch to slider menu with a menu icon on top
The options menu/action-bar-with-overflow is unrelated to the "slider menu". They serve different roles. Please read the design guidelines for a navigation drawer (a.k.a., "slider menu").
Is there an easy way to do this (I mean a way where code change would be minimum) retaining the existing functionality?
No, because they are not related.
I want to add a window on clicking the menu item of a right click popupmenu in Java swing(seems like a simple task...but not getting)
I got it to partly work by
adding a custom menuitem in popupmenu
adding a window on right click
But this only partly works. Now I when I right click anywhere a window pops up, but the selected menu item in the popupmenu does not pop up the window.
How can I get window on clicking my menu item? or is there an easier way to do this in java?
I know there are others ways of doing this (in code), but I would prefer to use Java swing
Has anyone ever done this before?
Thanks for your help
please to read Oracle tutorial about How to Use Menus
How to Use Swing Actions and / or with How to Write an Action Listener
a few examples about JPopup /JPopupMenu
I have a JTextPane sitting in a JFrame, with a popup menu that is assigned to the JTextPane through the JTextPane.setComponentPopupMenu method.
I want to give the JTextPane a "Word-like" popup behavior. By that I mean, if you right click outside of your current text selection, the caret will reposition to where you right clicked, with menu options that affect a text selection (such as cut, copy, or bold) disabled. If you right click within your current text selection, the popup will appear with options that effect text selection enabled, the text selection will persist, and the caret will not move.
The problem is I cannot seem to find where I can put the code that handles the selection change. I tried:
Using the "PopupMenuWillBecomeVisible" event which is triggered before a popup becomes visible. The event passed into this method does not contain any mouse event information so there is no way for me to use viewtomodel to find out how to modify the selection. I could use MouseInfo but that seems dubious at best.
Using MousePressed/MouseReleased events in the JTextPane or JFrame. Apparently, neither of these events are invoked when a popup menu is triggered. In fact, I still can't determine what the parent component of my popup menu is. (I did read that in windows "MouseReleased" is the popup trigger, while in other systems "MousePressed" is the trigger. I tried both and neither worked).
So, I guess the problem is that I can't seem to find a place to put code where it would be called before the popup menu becomes visible, but has awareness of the mouseEvent that triggered the popup menu. I must be missing something here.
with a popup menu that is assigned to the JTextPane through the JTextPane.setComponentPopupMenu method.
You can use the older approach of displaying the popup based on your own custom MouseListener.
See the section from the Swing tutorial on Bringing Up a Popup Menu. Now you have access to the MouseEvent so you can convert that point to a point in the Document so you know where the click was made, on selected or unselected text.