如何使用zk hbox数组?

发布于 2024-09-24 05:55:59 字数 1165 浏览 0 评论 0 原文

我不知道如何使用 zk Hbox 数组。我正在尝试创建 ZK Hbox 组件数组并在 for 块中使用它。

void createRow(Component container, final Node fieldNode, FieldCreator [] fieldDescription) {
    final Vbox fieldsRows = new Vbox();
    final Hbox fieldsRow = new Hbox();
    final Hbox[] fieldBox;

    int i=0;
    for (FieldCreator fieldDesc : fieldDescription) {
        fieldBox[i] = new Hbox();
        fieldDesc.createField(fieldNode, fieldBox[i]);
        i++;
    }
    fieldsRow.appendChild(fieldBox[]);
    Button removeFieldButton = new Button(Messages.getString("MXFC_removeFieldButton")); //$NON-NLS-1$
    fieldsRow.appendChild(removeFieldButton);
    fieldsRows.appendChild(fieldsRow);
    removeFieldButton.addEventListener(Events.ON_CLICK, new EventListener() {
        public void onEvent(Event event) throws Exception {
            fieldNode.getParentNode().removeChild(fieldNode);
            fieldBox[].setParent(null);
        }
    });
    container.appendChild(fieldsRows);
}

上面的代码不正确。编译器抛出错误:“标记“[”上的语法错误,此标记后需要表达式。”在线:

fieldsRow.appendChild(fieldBox[]);
fieldBox[].setParent(null);

我该如何解决这个问题?

谢谢, 索尼

I am not sure how to use a zk Hbox Array. I am trying to create an array of ZK Hbox components and use it within a for block.

void createRow(Component container, final Node fieldNode, FieldCreator [] fieldDescription) {
    final Vbox fieldsRows = new Vbox();
    final Hbox fieldsRow = new Hbox();
    final Hbox[] fieldBox;

    int i=0;
    for (FieldCreator fieldDesc : fieldDescription) {
        fieldBox[i] = new Hbox();
        fieldDesc.createField(fieldNode, fieldBox[i]);
        i++;
    }
    fieldsRow.appendChild(fieldBox[]);
    Button removeFieldButton = new Button(Messages.getString("MXFC_removeFieldButton")); //$NON-NLS-1$
    fieldsRow.appendChild(removeFieldButton);
    fieldsRows.appendChild(fieldsRow);
    removeFieldButton.addEventListener(Events.ON_CLICK, new EventListener() {
        public void onEvent(Event event) throws Exception {
            fieldNode.getParentNode().removeChild(fieldNode);
            fieldBox[].setParent(null);
        }
    });
    container.appendChild(fieldsRows);
}

The code above is incorrect. The compiler throws the error: "Syntax error on token "[", Expression expected after this token." on lines :

fieldsRow.appendChild(fieldBox[]);
fieldBox[].setParent(null);

How do I fix this?

Thanks,
Sony

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花想c 2024-10-01 05:55:59

索尼,

您的 java 代码中有一些语法错误。

  1. fieldBox[] 在 Java 中没有任何意义。
  2. 您需要先初始化 fieldBox,然后才能为其条目赋值。

为了解决这些问题,我们必须了解您想要在这段代码中实现什么目标。根据我的猜测,您应该

  1. 初始化fieldBox。

    Hbox[] fieldBox = new Hbox[fieldDescription.length];
  2. 在追加/分离行的子项时遍历列。

    for(int i=0; i

    for(int i=0; i

Sony,

There are a few syntax errors in your java code.

  1. fieldBox[] does not mean anything here in Java.
  2. You need to initialize fieldBox before you can assign value to its entries.

To fix these problems we have to understand what you want to achieve in this piece of code. Based on my guess, you should

  1. initialize fieldBox.

    Hbox[] fieldBox = new Hbox[fieldDescription.length];
  2. iterate through columns as you append/detach children of the row.

    for(int i=0; i<fieldBox.length; i++) fieldsRow.appendChild(fieldBox[i]);
    for(int i=0; i<fieldBox.length; i++) fieldBox[i].setParent(null);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文