B4J Library [Custom View] RichViewfx CodeArea

This is a custom view and very light wrapper for the RichTextFX Codearea from Thomas Mikula on github. There is enough in here to display code, useful for a snippets manager or similar.

RichViewfx.jpg

It is based on the example provided here: https://github.com/TomasMikula/RichTextFX#automatic-highlighting-of-java-keywords and modified with some, but I'm certain not all, B4x keywords and types.

It should provide a start to using the rest of the available views in that library.

You need to download the fat jar from the website listed under Manual Download from here:
https://github.com/TomasMikula/RichTextFX#download

and add it you your additional libraries folder.

In case they release a new version, make sure it's the same filename as in the additionalJar declaration at the top of the Main Module in the app. Otherwise, change the declaration.

The customview is usable from the designer and from code, and provides an editable CodeArea. It is simple to make it read only in the designer or in code (see the demo)

Requires B4j 4.20 Beta or later.

Have fun

Update: Added rfx-print, allows saving loading and printing of files and displaying Tabs as spaces.

rfxPrint requires:

jfx8Print ,

(Others Part of B4j distribution)
jSQL
jRandomAccessFile


Uses Standard Utilities (Included in the project file):
CSSUtils
KeyValueStore

Update rfx-print1.1: Improves cut and paste, allows cutting and pasting selections.
Update rfx-print1.2:
Add / Remove line numbers​
Improved regex matching​
Reposition cursor after cut / paste​
Printer font size is a better match to the screen display​
Update RichTextView0.2 and RichTextView-print1.3 updated to work with the latest fat-jar libraries (0,8.2 +) Also tested with 0.9.0


Note: if the combo box displays downwards - off the screen, then you need to download the latest Java jdk. This was a bug which has now been fixed.


Update to RichTextview-Print v 1.4 as a b4xlib to work with richtextfx-fat-0.10.5 which is downloadable from :https://github.com/FXMisc/RichTextFX.
I've also uploaded the code in a project file. (RichFX-Print.zip and RichFX-PrintB4xlib)

Information For those wanting to run on java > 8 you will need to add these lines to your project.

B4X:
#VirtualMachineArgs: --add-opens javafx.graphics/javafx.scene.text=ALL-UNNAMED  --add-exports javafx.graphics/com.sun.javafx.text=ALL-UNNAMED
#PackagerProperty: VMArgs = --add-opens javafx.graphics/javafx.scene.text=b4j --add-exports javafx.graphics/com.sun.javafx.text=b4j
249 209
 

Attachments

  • RichTextView.0.2.zip
    8.6 KB · Views: 749
  • RichTextView-print1.3.zip
    15.6 KB · Views: 694
  • RichFX-Print.zip
    12.8 KB · Views: 470
  • RichFX-PrintB4x.b4xlib
    9.3 KB · Views: 520
Last edited:

micro

Well-Known Member
Licensed User
Longtime User
Hi stevel05
thanks for your job.
Why the your example program crash a this line in CodeArea.bas?
B4X:
SpansBuilder.InitializeNewInstance("org.fxmisc.richtext.StyleSpansBuilder",Null)

Error:
B4X:
java.lang.ClassNotFoundException: org$fxmisc$richtext$StyleSpansBuilder

The latest version downloaded of richtextfx is richtextfx-fat-0.82.jar
 

ThRuST

Well-Known Member
Licensed User
Longtime User
What version of Java are you using? There might be compatible issues because of Java v9.0.1. It should probably work with an earlier version.
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Ok then that's not the problem. I used Steve05's CodeArea up to the version before Java 9.0.1 it worked fine before that. It might have been something else that caused my previous project to stop working so I rewrote the whole project again. I'm using a TextArea for my B4J project Athena that I posted in Share my creations.
You might want to ask Steve05 and he might take a look at it himself. If he's not too busy.
 

alienhunter

Active Member
Licensed User
Longtime User
Hi stevel05
thanks for your job.
Why the your example program crash a this line in CodeArea.bas?
B4X:
SpansBuilder.InitializeNewInstance("org.fxmisc.richtext.StyleSpansBuilder",Null)

Error:
B4X:
java.lang.ClassNotFoundException: org$fxmisc$richtext$StyleSpansBuilder

The latest version downloaded of richtextfx is richtextfx-fat-0.82.jar

it works this way

#AdditionalJar: richtextfx-fat-0.9.0

in CodeArea.bas
Dim SpansBuilder As JavaObject
SpansBuilder.InitializeNewInstance("org.fxmisc.richtext.model.StyleSpansBuilder",Null)
 

stevel05

Expert
Licensed User
Longtime User
Because the underlying library has changed. As Alien hunter as said, the class is now "org.fxmisc.richtext.model.StyleSpansBuilder"

I will update the lib when I get a chance.
 

ilan

Expert
Licensed User
Longtime User
hi, i am trying to run the example from post #1 but i get an error. i looked for the richtextfx-0.9.0.jar file on the guthub but it seems like it was updated to richtextfx-0.9.2.jar and now the b4j lib is not working.

any plans to update the lib?

thanx, ilan

logs:

Waiting for debugger to connect...
Program started.
java.lang.NoClassDefFoundError: org/fxmisc/flowless/Virtualized
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:274)
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:84)
at b4j.example.codearea._designercreateview(codearea.java:442)
at b4j.example.codearea._setup(codearea.java:139)
at b4j.example.main._appstart(main.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.start(main.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.fxmisc.flowless.Virtualized
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 79 more
java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/fxmisc/flowless/Virtualized
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.start(main.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: org/fxmisc/flowless/Virtualized
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:274)
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:84)
at b4j.example.codearea._designercreateview(codearea.java:442)
at b4j.example.codearea._setup(codearea.java:139)
at b4j.example.main._appstart(main.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
... 12 more
Caused by: java.lang.ClassNotFoundException: org.fxmisc.flowless.Virtualized
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 79 more
 

stevel05

Expert
Licensed User
Longtime User
Hi Ilan I will take a look, but as it may take a while, I've added a link to the 0.8.2 jar on my dropbox to the first post so that you can use it now.

Steve​
 

Mahimahi

Member
Licensed User
Hi, I am trying to switch from using TextArea to CodeArea to take advantage of highlighting of text. With TextArea I was able to resize when the main layout window resizes using .PrefWidth = MainLayoutForm.Width - x, and .PrefHeight = MainLayoutForm.Height - y. With CodeArea I tried doing .setup(MainLayoutForm, Null, 0, 400, MainLayoutForm.Width - x, MainLayoutForm.Height-y) which resizes the control initially when app starts, but while the window/main layout resizes, it doesn't seem to be resizing in MainLayoutForm_Resize event sub.

Can someone please give some pointers? Thanks a lot.
 

stevel05

Expert
Licensed User
Longtime User
From Alejandro Moyano's question, for those wanting to run Richviewfx on java > 8 you will need to add these lines to your project.

B4X:
#VirtualMachineArgs: --add-opens javafx.graphics/javafx.scene.text=ALL-UNNAMED  --add-exports javafx.graphics/com.sun.javafx.text=ALL-UNNAMED
#PackagerProperty: VMArgs = --add-opens javafx.graphics/javafx.scene.text=b4j --add-exports javafx.graphics/com.sun.javafx.text=b4j
 
Top