java - 如何在 Codename One 中应用多种布局?

标签 java layout codenameone

我一直在尝试自定义代号一中的商业主题。到目前为止我已经添加了额外的按钮。现在我正在尝试让这些按钮受到 y 轴框布局的约束,但我目前收到了 IllegalArgumentException。我已将表单设置为边框布局:

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();

最佳答案

框布局 Y 不是边框布局的约束。目前还不清楚您希望它看起来如何,但我猜您想要这样的东西,它将一个接一个地排列组件:

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();

以下是两个将框放置在边框布局父级中的嵌套示例:

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();

这可以简写为:

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();

关于java - 如何在 Codename One 中应用多种布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38334414/

相关文章:

codenameone - 代号一号中的股票行情模式

java - Gson LinkedTree 映射无法转换为 InformativeItemProvider

java - 如何以编程方式检查哪个 sim 卡被设置为 android 中的默认 sim 卡

java - 有什么方法可以重新排列java源文件中的导入

java - 多色列表

android - 3 个 textView 项目根据其长度换行

java - 自己的选项卡按钮容器: how to initialize all of them doing the same?

java - 为什么 Gson 在发布后改变属性?

javascript - 使用来自 json 响应的动态布局 : angularJS

arrays - 如何使用准备好的语句在代号 one db 中插入数据?