0

我不确定如何使用 zk Hbox Array。我正在尝试创建一个 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);

我该如何解决?

谢谢,索尼

4

1 回答 1

1

索尼,

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

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

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

  1. 初始化字段框。

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

    for(int i=0; i<fieldBox.length; i++) fieldsRow.appendChild(fieldBox[i]);
    for(int i=0; i<fieldBox.length; i++) fieldBox[i].setParent(null);
于 2010-09-21T07:00:01.073 回答