Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>PropertySheetPanel as is only populates its table reading the properties for a given Java Bean.</p> <p>You need to extend PropertySheetPanel behaviour and populate the properties from a given Collection. Iterate your collection and use addProperty(Property) to populate the table.</p> <p>You can also use <a href="http://java.sun.com/docs/books/tutorial/javabeans/introspection/index.html" rel="nofollow noreferrer">instrospection</a> or <a href="http://commons.apache.org/beanutils/" rel="nofollow noreferrer">beanutils</a> lib to discover the collection elements.</p> <p>EDIT: Example added.</p> <pre><code>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&lt;C&gt; 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&lt;C&gt; simpleModel) { super(); populateCollectionProperties(simpleModel); } private void populateCollectionProperties(Collection&lt;C&gt; 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&lt;Animal&gt;(getAnimals())); frame.pack(); frame.setVisible(true); } private Collection&lt;Animal&gt; getAnimals() { Collection&lt;Animal&gt; animals = new ArrayList&lt;Animal&gt;(); animals.add(new Animal("Lion", "Felidae")); animals.add(new Animal("Duck", "Anatidae")); animals.add(new Animal("Cat", "Felidae")); return animals; } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload