B4J Question Tray icon single click

ThRuST

Well-Known Member
Licensed User
Longtime User
In Windows 10, is it possible to single click or double click on the tray icon to perform an event? I've seen this possible in applications.
On Mac OSX however, single click on the tray icon is the default behavior.
 

ThRuST

Well-Known Member
Licensed User
Longtime User
I should have added that I meant left click in Windows is my desired behavior while I noticed that right click is the default to bring the popup menu up.
I assume the desired behavior can be controlled in the Click and DoubleClick events.

Is there a way to manually show or hide the popup menu as to decide if it should trigger from left or right button, or do something else like showing the pane instead of the menu?
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
What's the name of these events?
Sub Trayicon_MenuClick (Text As String) and _DoubleClick?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Sub spacebar and Tab was indeed useful. Thanks all of you for sorting this out 🙂👍

1599036146944.png
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
I ran into another problem, how to check if left mouse button is clicked. This is what I tried.
However an error occured saying MouseEvent object should first be initialized?

B4X:
Sub Trayicon_Click
   
    Dim event As MouseEvent
   
    If event.PrimaryButtonDown = True Then
        Xui.MsgboxAsync("Hello World!", "B4X")
    End If
   
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I ran into another problem, how to check if left mouse button is clicked. This is what I tried.
This cannot work. There is no relation between the MouseEvent object that you created and the actual event.

It is currently impossible to distinguish between the buttons without modifying the library code.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
To add this functionality would be most useful since it offers alot of flexibillity. With all respect, my request is posted here. Move it if you like. Thanks

B4X:
Sub Trayicon_Click (EventData As MouseEvent)
    
    If EventData.PrimaryButtonDown = True Then
        Xui.MsgboxAsync("Hello World!", "B4X")
    End If
    
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
JavaObject to the rescue:
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI 
    Private st As SystemTray
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    st.Initialize
    Dim icon As TrayIcon
    icon.Initialize("", xui.LoadBitmap(File.DirAssets, "logo.png"), Null)
    Dim jo As JavaObject = icon
    Dim event As Object = jo.CreateEventFromUI("java.awt.event.MouseListener", "MouseListener", Null)
    jo.RunMethod("addMouseListener", Array(event))
    st.AddTrayIcon(icon)
End Sub

Sub MouseListener_Event (MethodName As String, Args() As Object) As Object
    Log(MethodName)
    Dim MouseEvent As JavaObject = Args(0)
    Log(MouseEvent.RunMethod("getButton", Null))
    Return Null
End Sub

MouseEvent API: https://docs.oracle.com/javase/7/docs/api/java/awt/event/MouseEvent.html
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Erel Interesting workaround, but how do you bring up the popup menu? The event fires quickly and displays multiple messageboxes when used inside the sub.
Perhaps this can be prevented.

Another solution might be to use Roycefer's jAWTRobot library.
 
Upvote 0
Top