B4J Question B4xPages - Context menu

DarkoT

Active Member
Licensed User
Longtime User
Hi everyone,
I need help.

I'm trying to implement a context menu in a desktop app (B4J - B4XPages) that can be accessed by right-clicking on a panel or root view.
Is this possible?
Currently, I can only create a simple context menu that is attached to a button or label, but when I try to attach it to a panel or form, it gives me an error... see the highlighted part... Is this even possible to do?

[CODE lang="b4x" title="Example code" highlight="10, 11, 13"] Dim ctxMenu As ContextMenu
ctxMenu.Initialize("")
Dim MT() As String = Array As String("MI1","MI2","MI3")
For i = 0 To MT.Length - 1
Dim Mi As MenuItem
Mi.Initialize(MT(i),"ctxm")
ctxMenu.MenuItems.Add(Mi)
Next
' this line works and context menu is bound with button
' Dim v As B4XView = btnIzpisi
' v.As(JavaObject).RunMethod("setContextMenu",Array(ctxMenu))

' I want to bound context menu with pane or root.view or b4xtable
' HERE IS A ERROR - how can I bound context menu with f.e. b4xTable?! or panel (Pane)
Dim joTable As JavaObject = Root.GetView(0)
joTable.RunMethod("setContextMenu", Array(ctxMenu))[/CODE]

Error:

Error is in line: joTable.RunMethod("setContextMenu", Array(ctxMenu)

[CODE lang="b4x" title="Error"]WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
Error occurred on line: 88 (pgListaZaloga)
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:486)
at b4j.example.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:876)
at b4j.example.b4xpagesmanager._showpage(b4xpagesmanager.java:355)
at b4j.example.b4xpagesmanager._addpage(b4xpagesmanager.java:176)
at b4j.example.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:190)
at b4j.example.b4xpagesmanager._initialize(b4xpagesmanager.java:126)
at b4j.example.main._appstart(main.java:86)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at b4j.example.main.start(main.java:38)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:134)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:81)
... 35 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:115)
... 36 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:486)
at b4j.example.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:876)
at b4j.example.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:193)
at b4j.example.b4xpages._addpageandcreate(b4xpages.java:82)
at b4j.example.b4xmainpage._b4xpage_created(b4xmainpage.java:207)
... 41 more
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:134)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:81)
... 50 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:115)
... 51 more
Caused by: java.lang.RuntimeException: Method: setContextMenu not found in: anywheresoftware.b4j.objects.PaneWrapper$ConcretePaneWrapper$NonResizePane
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:363)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:120)
at b4j.example.pglistazaloga._initpage(pglistazaloga.java:224)
at b4j.example.pglistazaloga._b4xpage_created(pglistazaloga.java:102)
... 56 more
[/CODE]
 
Last edited:
Upvote 0
I'm trying to implement a context menu in a desktop app (B4J - B4XPages) that can be accessed by right-clicking on a panel or root view.
Is this possible?
Yes, you may place a label with size same as the root on the lowest layer of the layout
 

Attachments

Upvote 0
Yes, you may place a label with size same as the root on the lowest layer of the layout
This is really a cute 'workaround' solution... 😊

Yes, this idea could work, but I'm more interested in whether there is any way to avoid creating a 'label' for the whole screen (window) and instead attach a context menu to a pane or form.
Does this option even exist?
The problem is when I place the 'label' on form and on label then I need to place, for example,B4xTableView, which does not have an option to add a context menu. I want to have a context menu that is accessible for all objects in the form, not just for a label or button
 
Upvote 0
Yes, this idea could work, but I'm more interested in whether there is any way to avoid creating a 'label' for the whole screen (window) and instead attach a context menu to a pane or form.
Does this option even exist?
No, your log has already told you of the reason for the error, node and control are different, controls have the method setContextMenu, while node does not,that's why there was an error running the method setContextMenu with the pane.
 
Upvote 0
No, your log has already told you of the reason for the error, node and control are different, controls have the method setContextMenu, while node does not,that's why there was an error running the method setContextMenu with the pane.
aaaaa, okay, I understand...
But then I just need an idea on how to create a solution where a right mouse click (anywhere in the form) brings up a menu on the screen from which the user can select options related to this form/module?
 
Upvote 0
Upvote 0
For the Form or B4XPages layout, I would just (in the Designer) put all the views inside a pane that's anchored vertically and horizontally to its parent, full width and height - I think that's the easiest way to accomplish it.

I haven't looked at/tried it with a B4XTable, but according to https://www.b4x.com/android/forum/threads/b4x-b4xtable-with-custom-cells-layout.102352/ it is possible to implement a custom layout, so panes could provide a solution there too?
 
Upvote 0

Similar Threads

Back
Top