how to render TextArea or textField to vary font and color within the body of text

42 views
Skip to first unread message

shop.servic...@gmail.com

unread,
Apr 8, 2019, 1:32:25 PM4/8/19
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA NetBeans 8.2
Desktop OS Windows 10 Pro
Simulator Latest
Device PC, Android 7+ & IOS 12+

I am looking to vary font and color within the body of text.

In Swing I use HTML

Best approach would be appreciated.

Regards

Shai Almog

unread,
Apr 8, 2019, 11:48:03 PM4/8/19
to CodenameOne Discussions
You can use HTML but not in the body of arbitrary components which is super expensive. There is this option: https://www.codenameone.com/blog/tip-lightweight-rich-text-view.html

shop.servic...@gmail.com

unread,
Apr 9, 2019, 3:51:14 PM4/9/19
to CodenameOne Discussions
Thanks, however I don't like that lightweight option.

What does one use on Mobile devices to mix up fonts like size and color highlighting.
What is the preferred method?

Regards.

Dave Dyer

unread,
Apr 10, 2019, 12:13:59 AM4/10/19
to CodenameOne Discussions

I don't know of a general solution.  In my own universe I have a parallel to String called Text,
which allows mixed text fonts colors and icons.  Very handy once you have built out duplicates
for all th widgets that have String arguments.

Curse Java for making all the consumers of strings use actual Strings, which are
final, instead on interfaces.

Shai Almog

unread,
Apr 10, 2019, 12:44:39 AM4/10/19
to CodenameOne Discussions
You have two options. Either native HTML or do it yourself. The native HTML can only be rendered in a very specific component area. That's a platform specific limitation that we can't workaround.

shop.servic...@gmail.com

unread,
Apr 10, 2019, 8:47:47 AM4/10/19
to CodenameOne Discussions
Can you share the "text" Object and some examples of use?

It would be great if I were able to use mixed text fonts colors and icons.

Thanks in advance,

Regards.

Dave Dyer

unread,
Apr 10, 2019, 12:08:19 PM4/10/19
to CodenameOne Discussions
Text is an interface that mostly mimics strings, but it's part of a group of interfaces I use to build my GUIs, not something
you could just pull out and plug into your applications.  You have to take the whole village, and I haven't engineered the
villiage for export and general use.  

The key things are that Text has string-like methods such as "append" and "getWidth", and interfaces with a canvas proxy
that supports things like"draw".  I produce widgets that look like this using Text objects, using essentially the same logic that
was once based on strings. 

shop.servic...@gmail.com

unread,
Apr 11, 2019, 2:03:22 PM4/11/19
to CodenameOne Discussions
I understand, Thanks.
I can look deeper into the RichTextView class.

shop.servic...@gmail.com

unread,
Apr 11, 2019, 2:26:21 PM4/11/19
to CodenameOne Discussions
I see the simulator does not render any text.

Thoughts?

Regards.

Shai Almog

unread,
Apr 11, 2019, 10:28:57 PM4/11/19
to CodenameOne Discussions
There is an issue in that code discussed in the comments below. There is a newer improved version of the code in the Facebook Clone if you have the online courses. I'll try to dig through my code to find it and post an updated blog with that.

shop.servic...@gmail.com

unread,
Apr 12, 2019, 10:32:34 AM4/12/19
to CodenameOne Discussions
Thanks, I appreciate the effort.

The Question is Am I going down the wrong path?
I am 30 years in Swing designs and for the past 3 years have struggled to fully adapt to the mobile world in that my first instinct is to build screens with rich text components in mind.

Is there a standard to generate paragraphs for example that highlight text to present a decent look to the user with emphasis?

Regards.

Shai Almog

unread,
Apr 13, 2019, 1:23:29 AM4/13/19
to CodenameOne Discussions
There is no rich text standard across OS's. We looked a lot into that and it's a bit of a problem. We don't have that in our low level graphics API (rich drawString) so we can't implement something like Swings HTML subset everywhere functionality which was pretty cool. OTOH it was also problematic as if you'd use something like the font tag you'd mix design and implementation.

We have something better than the editor kit. It's the native browser component. It's really great at showing HTML, way better than anything in Swing. Unfortunately because it's a heavyweight component you shouldn't use it everywhere. The approach highlighted by the rich component is actually reasonable for simple cases. I used it a lot in the facebook clone. Notice in the screenshot below I use it for the terms which include links that invoke web pages.
Reply all
Reply to author
Forward
0 new messages