B4J Question HTMLEditor - how to scroll to the end of text

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings.

Erel was kind enough to provide me with a solution that positioned the cursor at the end of the text. I attach a project that demonstrates that functionality and illustrates the issue raised by the question below.

How to scroll the HTMLEditor to the end of the text?

Thank you for your replies.

Sandy
 

Attachments

  • 2 Text Editor V2_1.zip
    299.3 KB · Views: 218

Daestrum

Expert
Licensed User
Longtime User
You can use a robot ( com.sun.glass.ui.Application one) to do both things at once.
If you send the keystrokes "Ctrl END" it positions the cursor at the last character and also scrolls the window to the last line.

The basic code is : (robot and temp defined as javaobjects)
B4X:
Sub initRobot

robot = temp.InitializeStatic("com.sun.glass.ui.Application").RunMethodJO("GetApplication",Null).RunMethodJO("createRobot",Null)

End Sub
to use :
B4X:
Sub bottom
initRobot
Dim x,y As Int
x = MainForm.WindowLeft + HTMLEditor1.Left + 100 ' to get inside editor pane
y = MainForm.WindowTop + HTMLEditor1.Top + 160
robot.RunMethod("mouseMove",Array(x,y))
robot.RunMethod("mousePress",Array(1)) ' left click
robot.RunMethod("mouseRelease",Array(1)) ' release left button
robot.RunMethod("keyPress",Array(0x11)) ' ctrl
robot.RunMethod("keyPress",Array(0x23)) ' end
robot.RunMethod("keyRelease",Array(0x23)) ' end
robot.RunMethod("keyRelease",Array(0x11)) ' ctrl
End Sub
I added a button to your layout to call the 'bottom' sub and removed the setCursor routine altogether.
Also had to disable the save routine as the robot clicks in the pane and was saving the file each time lol.
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Inventive and creative indeed, Daestrum.

I implemented your solution and it works perfectly.

I had researched the topic on the web and I did not find even a hint as to how to do it.

Thank you so much.

Best regards.

Sandy
 
Upvote 0
Top