mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.14k stars 235 forks source link

Two types of cell renderers collide in a tree table #106

Closed Sciss closed 9 years ago

Sciss commented 10 years ago

I am using a TreeTable component. That basically nests JTrees inside a JTable. It works fine for most look-and-feels I have tested, but with WebLAF there is this oddity of two types of cell renderers: Table cells use blue background and white foreground, whereas trees (like lists) use a black outline instead. Somehow I end up having white text on light gray background (top to bottom: TreeTable/Tree/Table):

weblaf

In comparison, Nimbus:

nimbus

Is there a simple trick to configure a JList or a JTree to use table style cell rendering instead of the outline?

mgarin commented 10 years ago

It seems that this tree-table simply renders tree elements on top of the table cells using the tree renderer (that is fine, usually) together with table renderer (that is strange). And since in WebLaF tree renderer is totally different from table renderer you see this effect.

I guess tree renderer just needs a small patch for this specific case as it was not designed to be used this way. I will see what i can do about it.

mgarin commented 10 years ago

I just checked your TreeTable - it is a bit weird, the way you paint it I mean :) You are painting tree on top of the table, and of course you are getting such artifacts. This might also cause some other issues with other L&Fs - its just luck that Nimbus has similar table and tree cells display way by default.

But what is more important - tree selection you see (the gray one) comes from the tree itself, not the tree renderer. I have changed the way tree selection is painted a few versions ago to make it more convenient and customizable. So usually with components like Jide or NetBeans TreeTable you will never see it because they use only tree renderer and some custom painting to display cells. But in your case the whole tree is painted.

I am not sure how can i help with this situation.

Sciss commented 10 years ago

Ok, I found a work-around. In the TreeTable UI, I have to avoid setting the text foreground color for selected tree cells when WebLaF is active. That way, the default color (black) is retained and it looks readable again (although I'd generally prefer not to render the gray selection box at all).

mgarin commented 10 years ago

I think i will add an option to disable selection rendering in the tree background, that should actually fix your issue without affecting the way WebLaF works wit tree selection :)

Sciss commented 10 years ago

Ok, thanks. The best would be to use something similar to nimbus-overrides or a client property, that way I can change that settings independently of whether WebLaF is on the classpath or not.

stephanebruckert commented 9 years ago

The same happens with JXTreeTable from swingx. The default tree selection makes the whole treetable selection very buggy when used with weblaf.

Would you have a quick work-around to disable the gray selection box? Thanks

mgarin commented 9 years ago

I have added a small change that allows custom tree selection to be switched off.

It can be disabled globally:

WebTreeStyle.selectionStyle = TreeSelectionStyle.none;

Or for specific tree or UI instance:

final WebTree tree = new WebTree ();
tree.setSelectionStyle ( TreeSelectionStyle.none );
final JTree tree = new JTree ();
( ( WebTreeUI ) tree.getUI () ).setSelectionStyle ( TreeSelectionStyle.none );

So if you have access to tree table tree instance you can now switch it off so it doesn't interfere with selection painted by renderer or tree table component.

mgarin commented 9 years ago

I guess that should also close this question :) Still, if something is not yet right - feel free to reopen it.

stephanebruckert commented 9 years ago

Thanks, that's splendid!

However I could not specifically disable the selection style of my JXTreeTable because JXTreeTable.getUI() gives a TableUI and not a TreeUI. The global disabling worked though.

And for the other JTrees in my GUI, the selection style disappeared so I had to enable it again:

.setSelectionStyle ( TreeSelectionStyle.line );
mgarin commented 9 years ago

You might probably access the tree which JXTreeTable uses somehow. Probably through Reflection - it will still be better than override other trees style every time.

Or you can simply set global selection style to none before creating another JXTreeTable and then set it back to line after you have initialized it. That should initialize JXTreeTable with none style but will let you avoid customizing other trees.