1
votes

In Codename One, I need a class MyButton that extends Button. I want that every myButton instance is a Button which width and height are always equal (to the maximum of their values).

I know that every Component has setWidth and setHeight methods, but they are for the use of the layouts, I suppose that I should not use them directly.

I also know that I can create a Container with a custom layout and place a Button inside it... but in that case I’m not extending the Button class.

My question is if I can extend Button to create square buttons, or if the use of a Container with a custom layout is the only option.

1

1 Answers

1
votes

You can use GridLayout which gives everything the exact same width/height but I'm guessing that what you are looking for is:

Container.setSameSize(Component...);
Container.setSameWidth(Component...);
Container.setSameHeight(Component...);

It's static and the components don't need to be in the same container. They'll get the same width/height by returning the preferred width/height of the largest among the set.