B4J Question Check for selection in RichTextFX [SOLVED]

ThRuST

Well-Known Member
Licensed User
Longtime User
As the title says, is there an easy way to do that? my mind is blank after a long day with code so.. :)

Anyway, it's based on this

when a button is clicked..

B4X:
fx.Clipboard.SetString(CodeArea1.GetSelectedText) ' GetText selects all
 
Last edited:

ThRuST

Well-Known Member
Licensed User
Longtime User
a new day, another solution enjoy :)

B4X:
        ' Check for selected chars

        ' Nothing was selected
        If CodeArea1.GetSelectedText.Length <= 0 Then
   
            FXnotify.ShowNotification3("Athena", "Nothing was selected.", FXnotify.ICON_INFORMATION, MainForm, "CENTER", 3000)
   
            ' Something was selected
            else if CodeArea1.GetSelectedText.Length >=1 Then
   
            ' Fetch number of selected chars
            Private DummyLgt As Int = CodeArea1.GetSelectedText.Length
            FXnotify.ShowNotification3("Athena", "You selected " & DummyLgt & " chars.", FXnotify.ICON_INFORMATION, MainForm, "CENTER", 3000)
 
        End If
 
Last edited:
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
And here is the final preffered behavior. Depending on which TabPane is selected (Doc/Code as in Athena) , here's the logic.

If nothing is selected in the RichTextFX, then ALL the contents is copied to the clipboard.
If something is selected, that portion is copied to the clipboard.
This means, if the view is empty the clipboard becomes empty as well.

Info about project Athena can be found in B4J/Share my creations. Go here

B4X:
' Copy document or code depending on TabPane selection
    If TabPane.SelectedItem.Text.Trim = "Doc" Then
 
        Try
 
            ' Copy HTML-editor content to the clipboard
            fx.Clipboard.SetString(HTMLEditor1.HtmlText)
 
            ' Show Notification
            FXnotify.ShowNotification3("Athena", "Documentation was copied to the clipboard.", FXnotify.ICON_INFORMATION, MainForm, "CENTER", 3000)
 
        Catch
            Log(LastException)
        End Try
 
    End If
 
    ' Copy from Codeview instead
    If TabPane.SelectedItem.Text.Trim = "Code" Then
 
        Try
 
            ' Nothing was selected
            If CodeArea1.GetSelectedText.Length <= 0 Then
     
                ' Copy all content
                fx.Clipboard.SetString(CodeArea1.GetText)
     
                ' Show Notification
                FXnotify.ShowNotification3("Athena", "Code view content copied to clipboard.", FXnotify.ICON_INFORMATION, MainForm, "CENTER", 3000)
     
                ' Something was selected
                else if CodeArea1.GetSelectedText.Length >=1 Then
 
                ' Copy text to clipboard
                fx.Clipboard.SetString(CodeArea1.GetSelectedText)
     
                ' Show Notification
                FXnotify.ShowNotification3("Athena", "Code view Selection was copied to the clipboard.", FXnotify.ICON_INFORMATION, MainForm, "CENTER", 3000)
 
        End If
 
        Catch
            Log(LastException)
        End Try
 
    End If
 
Last edited:
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Mashiane Thanks :) I had to search Google to find out about length. It's indeed very powerful and most useful. The FXnotify is useful but will probably not be needed because sound themes has proven to be much more convenient. The RichTextFX was wrapped by Stevel05 and can be found in the forum, so you can use the classes he implemented right outa the box. There's also the option to print. It depends on Java 8 as there were no Java 11 support at the time he wrapped it. Actually he called it RichViewFX and it's available here
 
Upvote 0
Top