B4J Question How to Move an UNDECORATED Form

lymey

Active Member
Licensed User
Longtime User
Hi!
I am working on a java app where the form is a fixed size UNDECORATED or TRANSPARENT, and I want to be able to move the form in much the same way as you can with a DECORATED form.

What I am trying to do is to have custom controls/icons on a form, so I don't really want the 'decorations' but want to be able to move the form.

So far I have tried the MouseMove event (doesn't trap a mouse button is pressed event).
MouseDragged event is the most likley but obviously the mouse moves and you can't 'hold' the mouse in place while the form moves by resetting top and left coordinates.
MousePressed event is good for determining a mouse button is pressed, but other mouse events can't be trapped while the button is pressed.

The other alternative I suppose would be to try and disable the resize button so the form can be moved but the size of the form cannot change.

Any thoughts?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I am working on a java app where the form is a fixed size UNDECORATED or TRANSPARENT

I am working on a B4J app where the form is a fixed size UNDECORATED or TRANSPARENT...

Here:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private ox, oy As Double
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.SetFormStyle("UNDECORATED")
   MainForm.Show
   MainForm.RootPane.Style = "-fx-background-color: green;"
End Sub
Sub MainForm_MousePressed (EventData As MouseEvent)
   ox = EventData.X
   oy = EventData.Y
End Sub

Sub MainForm_MouseDragged (EventData As MouseEvent)
   Dim jo As JavaObject = EventData
   MainForm.WindowLeft = jo.RunMethod("getScreenX", Null) - ox
   MainForm.WindowTop = jo.RunMethod("getScreenY", Null) - oy
End Sub
In debug mode it is a bit jumpy. However the movement is smooth in Release mode.
 
Upvote 0
Top