Skip to content
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

DefaultCellRenderer ElementId #108

Open
Aufricer opened this issue May 13, 2022 · 2 comments
Open

DefaultCellRenderer ElementId #108

Aufricer opened this issue May 13, 2022 · 2 comments

Comments

@Aufricer
Copy link
Contributor

Aufricer commented May 13, 2022

Hi PSpeed,

I am trying to write a custom CellRenderer. That right now is nothing except
public class Picture_Renderer<T> extends DefaultCellRenderer {}

That in DefaulCellRenderer calls
public DefaultCellRenderer() { //this(new ElementId(Button.ELEMENT_ID), Styles.ROOT_STYLE, null); // I believe the above is a mistake as we should be using the default // style if none is specified. It is a change in behavior, though. // 2020-11-27 this(new ElementId(Button.ELEMENT_ID), null, null); }

setting the Element_ID to "button"
In Listbox , during making of the Element it calls

if( cellRenderer == null ) { // Create a default one cellRenderer = new DefaultCellRenderer<>(baseElementId.child("item"), style); } else { **cellRenderer.configureStyle(baseElementId.child("item"), style);** }
where it should set the elementID to list.item (what it is doing with the default one)

But unfort. in defaultCellRenderer it never overwrites the elementID as it is not null

@Override public void configureStyle( ElementId elementId, String style ) { if( this.elementId == null ) { this.elementId = elementId; } if( this.style == null ) { this.style = style; } }

Due to the "wrong" elementID there can be issues with the styling
grafik
--> See the cells have an own "visible" background while usually they dont
grafik

So - I will get around that but maybe it should be considered to either change the elementID in the constructor (why is it Button ?) or change the behaviour of public void configureStyle( ElementId elementId, String style ) to always let it set the style (do you mean
if(!( this.elementId == null )) insteadt of if( this.elementId == null ) ?

@pspeed42
Copy link
Contributor

pspeed42 commented May 13, 2022

configureStyle() should only change the style if the user hasn't already specified one. If the user specifies their own style then it is assumed to be better than one that the list box would force.

Most subclasses should use a real super constructor and not rely on the default. But for code that did rely on the default constructor, I could not lightly change the behavior for any code that was relying on it. Prior to list box enforcing its own child styles (like list item) listbox items were buttons by default. (In fact, that's what DefaultCellRenderer is creating in get view.)

When creating your own DefaultCellRenderer subclass, either specify the element ID you want or call the super constructor with null: super(null, null)
...then you will inherit the list's styling for items.

Note: it is also fine to ask these sorts of questions on the jMonkeyEngine forum if you like. Sometimes these messages get lost in the github spam and I don't see them until late. (I was lucky this time. :) )

@Aufricer
Copy link
Contributor Author

I will probably do. But as it is/was special usecases I am sometimes not sure it belongs to forum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants