JList performance when text is HTMML

Discuss here any questions about the WebLaF library.
Bugs can be posted directly to GitHub issues tracker.

JList performance when text is HTMML

Postby Abu Abdullah » Sat Sep 19, 2015 10:59 am

Hi Mikle,

I have JList with HTML text (only to change color). the list is slow when going up and down and when loading it. the size of the list can go up to 100.

there are few ways to improve such case by fixing the length and high but this does not help a lot. in addition, i tried to use the JLabel as ListCellRenderer (as per this http://stackoverflow.com/questions/3091816/displaying-large-jlist-formatted-as-html) but the style changed for the JList and the performance is still slow.

any suggestions will be appreciated.

The same for JTree

thanks
Abu Abdullah
 
Posts: 41
Joined: Tue Apr 17, 2012 12:11 pm

Re: JList performance when text is HTMML

Postby mgarin » Sat Sep 19, 2015 11:57 am

Generally - never use HTML in Swing components OR at least never use it inside of the renderer components. It is just slow and there is nothing to do with it unfortunately. It might be fine to use it inside some labels that are rendered once on the application, but even that is rarely the case, so I strongly recommend not to use it.

With JLabel/WebLabel you can change text color an font for the whole text inside the label and that will not affect the performance.

If you need to style different parts of label - you can use WebStyledLabel. Here is a small example:
Code: Select all
WebStyledLabel label = new WebStyledLabel ( "Sample {text:b} with {different:u;i} formatting {inside:b;c(125,115,255)}" );

It will not affect performance as it works times faster than HTML rendering and will style different parts of the text in label as you want them to be.

What you will see in this label when you launch it:
Sample text with different formatting inside


Syntax is pretty simple: {<your text>:<option1>;<option2>;...;<optionN>}
Full list of options (in current latest version):
p, plain - make text plain
b, bold - make text bold
i, italic - make text italic
u, underlined - make text underlined
s, strike - make text striked through
ds, doublestrike - make text striked through twice
sp, sup, superscript - place text as superscript
sb, sub, subscript - place text as subscript
c(r,g,b), color(r,g,b), f(r,g,b), foreground(r,g,b) - text foreground
b(r,g,b), background(r,g,b) - text background

Style options will be expanded in future, but current settings should be more than enough to create styled labels for any kind of renderers already.

Also WebStyledLabel supports line separation through "\n' and some other useful features.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: JList performance when text is HTML

Postby Abu Abdullah » Sat Sep 19, 2015 6:40 pm

thanks, this is great feature. it is the same or even better than JIDE styledLabel as the syntax is embedded in the string.

it loads faster but i have few points:
- RTL support is missing. if i starts using this, all the text will start from left. this is also the behavior in <HTML> tag but it can be solved using <div align=right>. how to achieve the same here
- How i can apply this approach to WebList. I have tried to setCellRenderer (new SearchListRenderer ()) but it didn't render correctly.

Code: Select all
class SearchListRenderer extends WebStyledLabel implements ListCellRenderer
    {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
        {
            setText(value.toString());
            return this;
        }
    }
Abu Abdullah
 
Posts: 41
Joined: Tue Apr 17, 2012 12:11 pm

Re: JList performance when text is HTMML

Postby mgarin » Sat Sep 19, 2015 7:39 pm

RTL support and other minor fixes and features were already added to WebStyledLabel in the styling branch which is not usable at the moment due to multiple other issues and incomplete changes. Those fixes and improvements will only be available in final v1.29 release as they include some newer elements which cannot be added into older version. I am working hard to finally pull this release right now.

Concerning the renderer - to use it properly it should consider selection display. Though in WebLaF selection is painted separately, so it should only have proper margins set and should not be opaque so that label text is not overlapping selection completely. You can look at how WebListCellRenderer class handles label and do the same with the WebStyledLabel:
https://github.com/mgarin/weblaf/blob/m ... derer.java
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: JList performance when text is HTMML

Postby Abu Abdullah » Sun Sep 20, 2015 4:34 pm

I tried the same but it seems setMargin has no effect. it might be convenient to have it supported in WebList out of the box
Abu Abdullah
 
Posts: 41
Joined: Tue Apr 17, 2012 12:11 pm

Re: JList performance when text is HTMML

Postby mgarin » Sun Sep 20, 2015 5:57 pm

That is actually a good idea, I will probably include this in the release along with other changes.

Regarding the margin - WebStyledLabel actually had some issues in earlier iterations with some settings and this is probably one of those. If margin doesn't work directly in WebStyledLabel or has some isses - you can use additional panel with margin that will host the label. That should not affect performance but will solve the issue till the release for you :)
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: JList performance when text is HTMML

Postby Abu Abdullah » Sun Sep 20, 2015 6:28 pm

thanks for your efforts. will wait for the update
Abu Abdullah
 
Posts: 41
Joined: Tue Apr 17, 2012 12:11 pm

Re: JList performance when text is HTMML

Postby mgarin » Tue Sep 22, 2015 1:19 am

I will put a separate note here when it is available.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg


Return to Questions

Who is online

Users browsing this forum: No registered users and 1 guest

cron