B4J Question A Window with NO focus

Starchild

Active Member
Licensed User
Longtime User
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.
 

Starchild

Active Member
Licensed User
Longtime User
@Erel posted this
https://www.b4x.com/android/forum/t...java-application-in-windows.99253/post-624929

It is a way to return focus to the form that had it originally - after clicking in another form.
The attached demo shows how it can be done.
Interesting. Unfortunately it is a Microsoft Windows solution only. Also assumes tha the form originally having focus is known.

This is why I was hoping to disable the stealing of focus by My Form, but still be able to click on a node on My Form.

Thanks anyway for the link and demo.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Have a look at 'setFocusTraversable' for a form - not used it or tried it though.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Only other way I can think of is to add an eventhandler to second form that consumes 'FOCUS' event
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
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
 
Upvote 0

Starchild

Active Member
Licensed User
Longtime User
I found this link to a post by Erel.
https://www.b4x.com/android/forum/threads/get-current-form.162078/#content

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
B4X:
x.InitializeStatic("anywheresoftware.b4a.objects.B4XViewWrapper$XUI").RunMethod("findActiveStage", Null)
 
Upvote 0

Starchild

Active Member
Licensed User
Longtime User
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
Yep. Alread found stage/requestFocus function. Seems to do what it says. Has possibility.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
This works too, without the need to store Stage
B4X:
Sub form2_FocusChanged (HasFocus As Boolean)
    If HasFocus Then
        MainForm.As(JavaObject).GetFieldJO("stage").RunMethod("requestFocus",Null)
    End If
End Sub
 
Upvote 0

Starchild

Active Member
Licensed User
Longtime User
Does it have to be a 2nd form?
Could it be a pane that you hide/show as needed, or move in & out of use like B4XDrawer?
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.
 
Upvote 0

Chris2

Active Member
Licensed User
Longtime User
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.
Does this help? https://www.b4x.com/android/forum/threads/find-the-focussed-view-in-a-pane.163332/post-1001846

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
 
Upvote 0

Starchild

Active Member
Licensed User
Longtime User
Does this help? https://www.b4x.com/android/forum/threads/find-the-focussed-view-in-a-pane.163332/post-1001846

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.
 
Upvote 0
Top