-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reflection error trying to set private field to a background color (custom JPanel) #110
Comments
Sorry for the delay, was away for two weeks. I guess your case is the one I didn't actually expect. I guess I will have to add some kind of ignored variables list into the This will look something like this: <skin>
<style type="panel" id="backgroundPanel" extends="default">
<component ignoredFields="background" />
</style>
</skin> Though that will also require a convenient way to register supported components into StyleManager and a few other improvements. I will add those changes in next update. |
In any case, since your reflection code does check for types (as far as I can see), the problem might be that it does not correctly distinguish between private fields of a class and a sub-class, otherwise it would have found that the type of that field is not You should probably be able to reproduce it like this:
So can I paste that XML fragment into some resource file to activate it? |
WebLaF doesn't actually check field type when setting value since it would reduce performance a lot. It simply tries to apply value specified in the style to the field in the component instance - it is up to you to provide proper style for each component. There are some predefined exceptions which may point to your mistakes so you can fix them quickly without digging into WebLaF code or looking for the cause in style. In your case exception is thrown outside of WebLaF but you can clearly see that WebLaF tried to set Field type is checked only when value is being read from the style XML in XStream converter for style object - otherwise I wouldn't be able to understand what am I reading at all. But it is checked in class associated with specified in style type: <skin>
<style type="panel" id="backgroundPanel" extends="default">
<component ignoredFields="background" />
</style>
</skin> You can see here So, no, you cannot fix this case yet. Example I have provided is just a preview of what you might need to add after the next update. I will explain it again as soon as I implement those features as I am not yet sure how it will function and look like. As you can see each separate part of WebLaF styling mechanism is pretty simple, but its behavior overall becomes really complicated and might cause unexpected issues. So I am still "in the middle of some calibrations" and any feedback is really appreciated :) |
Ok, thanks for the long explanation. I will see if I can perhaps use another sub-class which re-introduces a dummy |
That might fix the issue for now, indeed. Anyway, I will be adding those improvements for sure as issues similar to this one might be pretty common. |
… properties lists SupportedComponent class refactored
I have commited changes considering this case, here is the style you have to add to force skin to skip some specific property: <style type="panel" id="ignored-background" extends="default">
<component>
<background ignored="true" />
</component>
</style> For now you cannot add a custom supported component, so you will have to manually install styleId into your component that extends panel: StyleManager.setStyleId ( component, "ignored-background" ); As soon as custom component support registration will be added you will be able to register specific style types for your own component and skip applying the style for each component instance - default style will be applied automatically. |
By the way, similar technique can used to ignore any other field in component/ui/painter. <field-name ignored="true" /> |
Have you tried this fix yet by any chance? |
I just tried. It seems to work now, actually without me having to add any xml specification. (The exception has disappeared). I think this issue can be closed. |
Probably some other changes I have made to StyleManager covered this case as well. |
Which commit corresponds to v1.28 - the latest one? I will publish again an artifact on Maven Central, so I can use this new version via Maven. |
What do you mean under "corresponds to v1.28"? |
Ah, sorry, misread |
Those changes are now available in v1.28 update: |
It seems that WebLaF is using heavy reflection to "poke" into private fields of components. I don't know exactly why it's doing that but it runs into a problem with DockingFrames:
It seems that WebPanelUI assumes there is a field
background
which is of typejava.awt.Color
. This is a private field inJComponent
perhaps, but the component in question here, has the following:So this throws a reflection error. It is caught, but means that the console is full of stack traces. Somehow the reflection check against the field type must go wrong.
The text was updated successfully, but these errors were encountered: