I have been trying to customize the business theme in Codename One. So far I have added extra buttons. Right now I am trying to get those buttons to be constrained by a y- axis boxlayout, but I am currently getting a IllegalArgumentException
. I have set the form to a border layout:
Form hi = new Form("Welcome", new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
Button Customer = new Button("Customer");
Button gpsProduct = new Button("Find A product Near You");
Button learnMore = new Button("Learn More");
Button Website = new Button("Visit Our Website");
hi.add(BoxLayout.Y_AXIS, Customer).
add(BoxLayout.Y_AXIS, learnMore).
add(BoxLayout.Y_AXIS, gpsProduct).
add(BoxLayout.Y_AXIS, Website);
hi.show();
Box layout Y isn't a constraint for border layout. It's unclear how you wanted this to look but I'm guessing you want something like this which will arrange the components one after the other:
Form hi = new Form("Welcome", BoxLayout.y());
Button Customer = new Button("Customer");
Button gpsProduct = new Button("Find A product Near You");
Button learnMore = new Button("Learn More");
Button Website = new Button("Visit Our Website");
hi.add(Customer).
add(learnMore).
add(gpsProduct).
add(Website);
hi.show();
Here are two nested examples that place the box in a border layout parent:
Form hi = new Form("Welcome", new BorderLayout());
Button Customer = new Button("Customer");
Button gpsProduct = new Button("Find A product Near You");
Button learnMore = new Button("Learn More");
Button Website = new Button("Visit Our Website");
Container box = new Container(BoxLayout.y());
box.add(Customer).
add(learnMore).
add(gpsProduct).
add(Website);
hi.add(BorderLayout.CENTER, box);
hi.show();
This can be written in shorthand as:
Form hi = new Form("Welcome", new BorderLayout());
Button Customer = new Button("Customer");
Button gpsProduct = new Button("Find A product Near You");
Button learnMore = new Button("Learn More");
Button Website = new Button("Visit Our Website");
hi.add(BorderLayout.CENTER,
BoxLayout.encloseY(Customer, learnMore, gpsProduct, Website););
hi.show();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.