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

When i want replace my descriptor , it does not work #670

Open kalshen2018 opened 3 years ago

kalshen2018 commented 3 years ago

I rewrite ImagePainter.java -> MyImagePainter.java and create new descriptor

public final class MyImageDescriptor extends AbstractImageDescriptor<WebImage, WImageUI, IImagePainter>
{
    /**
     * Constructs new {@link ImageDescriptor}.
     */
    public MyImageDescriptor()
    {
        super (
                "image",
                WebImage.class,
                "ImageUI",
                WImageUI.class,
                WebImageUI.class,
                IImagePainter.class,
                MyImagePainter.class,
                AdaptiveImagePainter.class,
                StyleId.image
        );
    }
}

and in my main function

main(){
...
  WebLookAndFeel.install();
  StyleManager.registerComponentDescriptor(new MyImageDescriptor());
}
mgarin commented 3 years ago

The main issue here is that you need to initialize all custom descriptors before you install L&F:

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

This should fix the problem.

Unfortunately there is no good way to apply descriptor changes after L&F initialization yet, I might get around to find a solution for this later but for now it can only be done before L&F is installed.


I apologize for the very late response, notifications for a few last issues got somehow lost in the mail.

mgarin commented 3 years ago

I might have actually been wrong since I didn't touch that part of WebLaF for a while. Your original order of operations was actually correct:

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

But what exactly doesn't work in that case? Your MyImagePainter doesn't get called or?

mgarin commented 3 years ago

I might have an idea what could be wrong, as I mentioned in #673:

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 MyImageDescriptor () );
StyleManager.setSkin ( new WebLightSkin () );

(or whichever skin you're using)

kalshen2018 commented 3 years ago

Thank you for your reply. I see the same issue in #673 , I will reapply skin after descriptors modification and reply to you in a few days .