I am using SwingMetaWidget. In my code I have a Dialog to which I pass a domain object dynamically and that will lead to different number of components based on the domain object. I would like the metawidget to return its preferredSize based on the inspection results. How can I achieve this. To illustrate my point, let us look at the Tutorial example.
Main Code:
package com.myapp;
import javax.swing.*;
import org.metawidget.swing.*;
public class Main {
public static void main( String[] args ) {
Person person = new Person();
SwingMetawidget metawidget = new SwingMetawidget();
metawidget.setToInspect( person );
JFrame frame = new JFrame( "Metawidget Tutorial" );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.getContentPane().add( metawidget );
frame.setSize( 400, 250 );
frame.setVisible( true );
}
}
Domain Object:
package com.myapp;
public class Person {
private String mName;
private int mAge;
private boolean mRetired;
public String getName() { return mName; }
public void setName( String name ) { mName = name; }
public int getAge() { return mAge; }
public void setAge( int age ) { mAge = age; }
public boolean isRetired() { return mRetired; }
public void setRetired( boolean retired ) { mRetired = retired; }
}
If I remove the line 'frame.setSize( 400, 250 );' the Frame completely collapses and shows nothing. Image of Collapsed Frame
Is there a way to show just enough of the JFrame to see all the components of the Metawidget(I will need to call pack() of the JFrame)? I am more concerned about the height. I can set a fixed width for it.