كيفية استخدام صفيف 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 [] لا يعني أي شيء هنا في جافا.
- تحتاج إلى تهيئة FieldBox قبل أن تتمكن من تعيين قيمة لإدخالاتها.
لإصلاح هذه المشكلات ، علينا أن نفهم ما تريد تحقيقه في هذه الكود. بناءً على تخميني ، يجب عليك
تهيئة FieldBox.
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