views:

36

answers:

1

Hi,

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

+1  A: 

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