Объявите переменную с let
вместо var
, что создаст отдельную область.
for (let i=0; i
PropertySheetPanel как есть только заполняет свою таблицу, читая свойства для данного Java Bean.
Вам необходимо расширить поведение PropertySheetPanel и заполнить свойства из данной коллекции. Итерируйте свою коллекцию и используйте addProperty (Property) для заполнения таблицы.
Вы также можете использовать instrospection или beanutils lib для обнаружения элементов коллекции.
EDIT: Пример добавлен .
package com.stackoverflow.swing.PropertySheetPanel;
import java.util.ArrayList;
import java.util.Collection;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import com.l2fprod.common.propertysheet.DefaultProperty;
import com.l2fprod.common.propertysheet.PropertySheetPanel;
/**
* An example that creates a l2fprod PropertySheetPanel that displays any
* Collection.
*/
public class CollectionPropertySheet<C> extends PropertySheetPanel {
// Choose some bean. An animal as example.
static class Animal {
private String name;
private String family;
public Animal(String name, String family) {
this.name = name;
this.family = family;
}
@Override public String toString() {
return name + " " + family;
}
}
/**
* @param simpleModel The input collection as data model.
*/
public CollectionPropertySheet(Collection<C> simpleModel) {
super();
populateCollectionProperties(simpleModel);
}
private void populateCollectionProperties(Collection<C> collection) {
int index = 0;
for (C entry : collection) {
// Define property properties
DefaultProperty property = new DefaultProperty();
property.setDisplayName(entry.getClass().getSimpleName() + "[" + index++ +"]");
property.setValue(entry.toString());
// Set any other properties ...
// and add.
addProperty(property);
}
}
// Start me here!
public static void main(String[] args) {
// Inside EDT
SwingUtilities.invokeLater(new Runnable() {
@Override public void run() {
JFrame frame = new JFrame("A simple example...");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new CollectionPropertySheet<Animal>(getAnimals()));
frame.pack();
frame.setVisible(true);
}
private Collection<Animal> getAnimals() {
Collection<Animal> animals = new ArrayList<Animal>();
animals.add(new Animal("Lion", "Felidae"));
animals.add(new Animal("Duck", "Anatidae"));
animals.add(new Animal("Cat", "Felidae"));
return animals;
}
});
}
}