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

MyTreeDescriptor invalid ,not use MyTreePainter #673

Open xcfdszzr opened 3 years ago

xcfdszzr commented 3 years ago
 public final class MyTreeDescriptor extends AbstractTreeDescriptor<MyTree, WTreeUI, ITreePainter>
 {
      public MyTreeDescriptor()
      {

          super (
                  "tree",
                  WebTree.class,
                  "TreeUI",
                  WTreeUI.class,
                  MyWebTreeUi.class,
                  ITreePainter.class,
                  MyTreePainter.class,
                  AdaptiveTreePainter.class,
                  StyleId.tree
          );
          System.out.println("MyTreeDescriptor");
      }
 }

define self TreePainter

public class MyTreePainter<C extends JTree, U extends WTreeUI, D extends IDecoration<C, D>> extends AbstractDecorationPainter<C, U, D>
    implements ITreePainter<C, U> {

    public MyTreePainter() {
    System.out.println(" MyTreePainter");
   ...............
}

register MyTreeDescriptor

            StyleManager.registerComponentDescriptor(new MyTreeDescriptor());
            WebLookAndFeel.install();

but MyWebTreeUi and MyTreePainter not Be used in new WebTree();

mgarin commented 3 years ago

I might have actually been wrong in #670 - this IS the correct order of descriptor registration:

WebLookAndFeel.install ();
StyleManager.registerComponentDescriptor ( new MyTreeDescriptor () );

That being said, I have a feeling that even with that order of operations - painters will not be overridden because they are loaded with skin and aren't updated after WebLookAndFeel.install (); call is finished.

Would it help if you reapply skin after descriptors modification?

WebLookAndFeel.install ();
StyleManager.registerComponentDescriptor ( new MyTreeDescriptor () );
StyleManager.setSkin ( new WebLightSkin () );

(or whichever skin you're using)

xcfdszzr commented 3 years ago
 Thank you very much,
 My problem is solved
Love you, the author
mgarin commented 3 years ago

Generally this does look like a bug, even though technically it isn't. Problem lies in initialization order hidden behind L&F installation - there is just too much stuff there that is being initialized at once.

I'll think about how this can be improved in future updates to avoid confusion.

Thanks for reporting this issue! I'll leave it open for now and change it to bug.