Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
'===== make up some controls =====
'===== and initialize them
Dim t As TextField
Dim im As Image
Dim iv As ImageView
Dim sl As Slider
sl.Initialize("")
im.Initialize("c:/temp/","arr_right.png")' any old picture not too big, remember its in a menu
iv.Initialize("iv")
iv.SetImage(im)
t.Initialize("")
Dim jo,jo1 As JavaObject ' dont forget to add javaobject library
Dim cm As ContextMenu
cm.Initialize("") ' init contextmenu dont want handler
' ===== initialize the 'Custom menu items"
jo.InitializeNewInstance("javafx.scene.control.CustomMenuItem",Array(iv))
jo.RunMethod("setHideOnClick",Array(True)) ' disappear when clicked
jo1.InitializeNewInstance("javafx.scene.control.CustomMenuItem",Array(sl))
jo1.RunMethod("setHideOnClick",Array(False)) ' dont disappear when clicked
cm.MenuItems.AddAll(Array(jo,jo1)) ' add to context menu
t.ContextMenu = cm ' bind menu to textfield
MainForm.RootPane.AddNode(t,50,50,-1,-1) ' add textfield to form
End Sub
Sub iv_MouseClicked(eventdata As MouseEvent) ' called when image in menu clicked
Log("clicked " & Sender)
End Sub
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim cm As ContextMenu
Dim b As Button
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Show
cm.Initialize("cm")
Dim mi As MenuItem
mi.Initialize("item 1", "item1")
cm.MenuItems.Add(mi)
b.Initialize("b")
MainForm.RootPane.AddNode(b, 100, 100, 100, 100)
End Sub
Sub MainForm_MouseClicked (EventData As MouseEvent)
Dim jo As JavaObject = cm
jo.RunMethod("show", Array(b, MainForm.WindowLeft + b.Left + 20, _
MainForm.WindowTop + b.Top + 50))
End Sub
Sub item1_Action
Log("click")
End Sub
B4X:jo.RunMethod("show", Array(b, MainForm.WindowLeft + b.Left + 20, _ MainForm.WindowTop + b.Top + 50))
jo.RunMethod("show", Array as Object(b, MainForm.WindowLeft + b.Left + 20, _
MainForm.WindowTop + b.Top + 50))
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim cm As ContextMenu
Dim mi As MenuItem
Dim jBeep As JavaObject
jBeep.InitializeStatic("java.awt.Toolkit")
jBeep = jBeep.RunMethod("getDefaultToolkit", Null)
Dim lb1 As Label
Dim jo As JavaObject
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
' MainForm.Resizable = False
' MainForm.SetFormStyle("UTILITY")
lb1.Initialize("")
MainForm.RootPane.AddNode(lb1, 100,300,300,100)
MainForm.Show
Dim smiClass As String = "javafx.scene.control.SeparatorMenuItem"
Dim smi() As Object = Array(jo.InitializeNewInstance(smiClass,Null), _
jo.InitializeNewInstance(smiClass,Null))
cm.Initialize("")
mi.Initialize("MenuItem1","MenuItem1")
cm.MenuItems.Add(mi)
cm.MenuItems.Add(smi(0))
mi.Initialize("MenuItem2","MenuItem2")
cm.MenuItems.Add(mi)
cm.MenuItems.Add(smi(1))
mi.Initialize("MenuItem3","MenuItem3")
cm.MenuItems.Add(mi)
End Sub
Sub MainForm_MouseReleased(mData As MouseEvent)
jo = cm
If mData.SecondaryButtonPressed Then
jo.RunMethod("show", Array(MainForm.RootPane, _
MainForm.WindowLeft + MainForm.WindowWidth - MainForm.Width - 8 + mData.x, _
MainForm.WindowTop + MainForm.WindowHeight - MainForm.Height - 8 + mData.y))
Else
jo.RunMethod("hide",Null)
End If
End Sub
Sub MenuItem1_Action
lb1.Text = "MenuItem1 was fired"
Beep
End Sub
Sub MenuItem2_Action
lb1.Text = "MenuItem2 was fired"
Beep
End Sub
Sub MenuItem3_Action
lb1.Text = "MenuItem3 was fired"
Beep
End Sub
Sub Beep
jBeep.RunMethod("beep", Null)
End Sub
cm.Initialize("")
mi.Initialize("MenuItem1","MenuItem1")
cm.MenuItems.Add(mi)
cm.MenuItems.Add(smi(0))
mi.Initialize("MenuItem2","MenuItem2")
cm.MenuItems.Add(mi)
cm.MenuItems.Add(smi(1))
mi.Initialize("MenuItem3","MenuItem3")
cm.MenuItems.Add(mi)
cm.Initialize("")
mi.Initialize("MenuItem1","MenuItem")
cm.MenuItems.Add(mi)
cm.MenuItems.Add(smi(0))
mi.Initialize("MenuItem2","MenuItem")
cm.MenuItems.Add(mi)
cm.MenuItems.Add(smi(1))
mi.Initialize("MenuItem3","MenuItem")
cm.MenuItems.Add(mi)
...
Sub MenuItem_Action
Dim Mitem as MenuItem = Sender
lb1.Text = Mitem.Text & " was fired"
Beep
End Sub
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?