In a B4J application, I am trying to create a window that never takes focus away from another window, even when its button or Image nodes are themselves clicked. Something similar to the Virtual Keyboard implementation in JavaFX itself.
Possibly creating a STAGE/SCENE that is not a Window that holds my NODES, or disabling the FOCUS EVENT of a window.
Any idea or Code snippet would be appreciated.
Try this - see if its suitable for you (uses JavaObject library)
B4X:
Sub Process_Globals
...
DIm Stage as JavaObject
...
End Sub
Sub AppStart (Form1 As Form, Args() As String)
...
'get mainwindow stage in AppStart
Stage = MainForm.As(JavaObject).GetFieldJO("stage")
...
End Sub
'form2 is second window
Sub form2_FocusChanged (HasFocus As Boolean)
If HasFocus Then
Stage.RunMethod("requestFocus",Null)
End If
End Sub
It has a function for obtaining the FORM that is currently in FOCUS.
Unfortunately for me, is relies on the B4X library XUI, which I am not using.
I can include the XUI library, but it a lot of extra sludge in my final JAR that I don't otherwise need.
Just wondering if there is an alternative function in the B4J CORE library to
Try this - see if its suitable for you (uses JavaObject library)
B4X:
Sub Process_Globals
...
DIm Stage as JavaObject
...
End Sub
Sub AppStart (Form1 As Form, Args() As String)
...
'get mainwindow stage in AppStart
Stage = MainForm.As(JavaObject).GetFieldJO("stage")
...
End Sub
'form2 is second window
Sub form2_FocusChanged (HasFocus As Boolean)
If HasFocus Then
Stage.RunMethod("requestFocus",Null)
End If
End Sub
Sub form2_FocusChanged (HasFocus As Boolean)
If HasFocus Then
MainForm.As(JavaObject).GetFieldJO("stage").RunMethod("requestFocus",Null)
End If
End Sub
I haven't looked much at the B4X suite of views etc.
I've gotta say, the B4XDrawer looks great, but not something I can apply to what I am doing.
I have a B4J application that has many windows/forms that are instances of the same class, each displaying/controlling different things. Think of my problem as having a Utility/tools Window/Form that is used to affect the views an each of the instantiated Windows/Forms. I need to retain focus so that the selected Utility/Tool can affect the view in focus (on one of the other Windows/Form.
I think I am getting close to a workable solution. Just hoping I can get an answer on the issue stated in the above post #10 relating to re-writting Erel's "GetCurrentForm" function without needing to introduce the XUI library into my application.
Just hoping I can get an answer on the issue stated in the above post #10 relating to re-writting Erel's "GetCurrentForm" function without needing to introduce the XUI library into my application.
As an alternative, can you not just keep a global reference to the last view the user clicked on?
B4X:
Public ActiveView as B4XView 'e.g. in a module named 'PublicViews'
'Main form
Private Sub txt_MouseClicked (EventData As MouseEvent)
PublicViews.ActiveView = Sender
End Sub
'Tools form
Private Sub btnOnToolForm_Click (EventData As MouseEvent)
PublicViews.ActiveView.Text = "I'm the active view"
End Sub
As an alternative, can you not just keep a global reference to the last view the user clicked on?
B4X:
Public ActiveView as B4XView 'e.g. in a module named 'PublicViews'
'Main form
Private Sub txt_MouseClicked (EventData As MouseEvent)
PublicViews.ActiveView = Sender
End Sub
'Tools form
Private Sub btnOnToolForm_Click (EventData As MouseEvent)
PublicViews.ActiveView.Text = "I'm the active view"
End Sub
I had the same idea. But using a global to keep track of the last active Window/Form.
in the B4J event, "Form_FocusChanged(..)"
and then using the Stage/requestFocus to restore focus to that Window/Form.