Example #1
0
    public void propertyChange(PropertyChangeEvent evt) {
      if (evt.getNewValue() == evt.getOldValue()) {
        return;
      }
      if (evt.getPropertyName().equals(key) && evt.getNewValue() != null) {
        removeAll();
        propertyTables = new ArrayList<PropertyTable>();
        switch (type) {
          case LIST:
            List<?> l = (List<?>) evt.getNewValue();

            final JPanel panel = new JPanel();
            panel.setBorder(BorderFactory.createEmptyBorder());
            GroupLayout layout = new GroupLayout(panel);
            panel.setLayout(layout);
            GroupLayout.ParallelGroup horizontal = layout.createParallelGroup();
            GroupLayout.SequentialGroup vertical = layout.createSequentialGroup();
            for (int i = 0, size = l.size(); i < size; i++) {
              PropertyTable table = new PropertyTable(l.get(i), extractor);
              propertyTables.add(table);
              JTableHeader tableHeader = table.getTableHeader();
              horizontal.add(
                  layout.createParallelGroup(GroupLayout.LEADING).add(tableHeader).add(table));
              vertical.add(layout.createSequentialGroup().add(tableHeader).add(table));
            }
            layout.setHorizontalGroup(horizontal);
            layout.setVerticalGroup(vertical);
            add(new JScrollPane(panel), BorderLayout.CENTER);
            break;
          case TABLE:
            PropertyTable table = new PropertyTable(evt.getNewValue(), extractor);
            propertyTables.add(table);
            add(new JScrollPane(table), BorderLayout.CENTER);
            break;
        }

        repaint();
        getParent().validate();
      }
    }
  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel(QuaquaLookAndFeel.class.getName());
    } catch (Exception e) {
    }

    JFrame frame = new JFrame("OSXFORMTEST");
    JPanel panel = new JPanel();
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);

    if (UIManager.getLookAndFeel().getID().equals("Aqua")) {
      layout.setAutocreateGaps(true);
      layout.setAutocreateContainerGaps(true);
    }

    JLabel artistLabel = new JLabel("Artist");
    JLabel albumLabel = new JLabel("Album");
    JTextField artist = new JTextField("Sonic Youth");
    JTextField album = new JTextField("Bad Moon Rising");

    int labelAlignment =
        UIManager.getLookAndFeel().getID().equals("Aqua")
            ? GroupLayout.TRAILING
            : GroupLayout.LEADING;

    GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();
    hGroup.add(layout.createParallelGroup(labelAlignment).add(artistLabel).add(albumLabel));
    hGroup.add(layout.createParallelGroup().add(artist).add(album));
    layout.setHorizontalGroup(hGroup);

    GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
    vGroup.add(layout.createParallelGroup(GroupLayout.BASELINE).add(artistLabel).add(artist));
    vGroup.add(layout.createParallelGroup(GroupLayout.BASELINE).add(albumLabel).add(album));
    layout.setVerticalGroup(vGroup);
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
  }