如何使用ZK Hbox数组?
-
04-10-2019 - |
题
我不确定如何使用ZK Hbox数组。我正在尝试创建一个ZK Hbox组件的数组,并将其在用于块中。
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);
我该如何解决?
谢谢,索尼
解决方案
索尼,
Java代码中有一些语法错误。
- fieldbox []在Java中并不意味着任何内容。
- 您需要初始化字段框,然后才能为其条目分配值。
要解决这些问题,我们必须了解您在此代码中要实现的目标。根据我的猜测,你应该
初始化字段框。
Hbox[] fieldBox = new Hbox[fieldDescription.length];
当您附加/分离该行的孩子时,通过列迭代。
for(int i=0; i<fieldBox.length; i++) fieldsRow.appendChild(fieldBox[i]);
for(int i=0; i<fieldBox.length; i++) fieldBox[i].setParent(null);
不隶属于 StackOverflow