|
JFormDesigner 5.0.4 Runtime API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jformdesigner.runtime.FormCreator
public class FormCreator
Creates instances of Swing components from a form model and
provides methods to access components.
Use FormLoader
to load a form model from a JFormDesigner
.jfd file into memory.
First invoke one of the create
methods.
Then you can use the getter methods to access the created Swing components.
Use the standard Swing methods to add listeners, set values or get values.
Example:
// load the .jfd file into memory FormModel formModel = FormLoader.load( "com/jformdesigner/examples/LoaderExample.jfd" ); // create a dialog FormCreator formCreator = new FormCreator( formModel ); JDialog dialog = formCreator.createDialog( null ); // get references to components JTextField nameField = formCreator.getTextField( "nameField" ); JCheckBox checkBox = formCreator.getCheckBox( "checkBox" ); JButton okButton = formCreator.getButton( "okButton" ); // set values and add listeners nameField.setText( "enter name here" ); okButton.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { // add your code... } } ); // show dialog dialog.setModal( true ); dialog.pack(); dialog.show(); System.out.println( nameField.getText() ); System.out.println( checkBox.isSelected() );
If you've assigned event handlers in the form, use setTarget(Object)
to set a target for the events.
Constructor Summary | |
---|---|
FormCreator(FormModel model)
Creates a new FormCreator for the specified form model. |
|
FormCreator(FormModel model,
java.lang.ClassLoader classLoader)
Creates a new FormCreator for the specified form model
using the specified class loader. |
|
FormCreator(FormModel model,
java.util.Locale locale,
java.lang.ClassLoader classLoader)
Creates a new FormCreator for the specified form model
using the specified locale and class loader. |
Method Summary | |
---|---|
java.awt.Component |
create()
Creates the component hierarchy for the first top level form component. |
java.awt.Component |
create(java.lang.String name)
Creates the component hierarchy for the specified name. |
java.awt.Component |
create(java.lang.String name,
java.awt.Window owner)
Creates the component hierarchy for the specified name and passes the specified owner window to the constructor, if the component is an instance of java.awt.Window . |
void |
createAll()
Creates all components. |
java.lang.Object[] |
createBindings()
Creates the bindings. |
javax.swing.JDialog |
createDialog(java.awt.Window owner)
Creates the component hierarchy for the first top level form component, which must be an instance of javax.swing.JDialog . |
javax.swing.JPanel |
createPanel()
Creates the component hierarchy for the first top level form component, which must be an instance of javax.swing.JPanel . |
java.awt.Window |
createWindow(java.awt.Window owner)
Creates the component hierarchy for the first top level form component, which must be an instance of java.awt.Window . |
java.lang.Object |
getBean(java.lang.String name)
Returns the bean for the specified name. |
java.lang.Object |
getBean(java.lang.String name,
boolean create)
Returns the bean for the specified name. |
javax.swing.JButton |
getButton(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JCheckBox |
getCheckBox(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JCheckBoxMenuItem |
getCheckBoxMenuItem(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JComboBox |
getComboBox(java.lang.String name)
Returns the component for the specified name. |
java.awt.Component |
getComponent(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JDialog |
getDialog(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JEditorPane |
getEditorPane(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JFormattedTextField |
getFormattedTextField(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JFrame |
getFrame(java.lang.String name)
Returns the component for the specified name. |
protected java.util.ResourceBundle |
getI18nBundle(java.lang.String baseName,
java.util.Locale locale,
java.lang.ClassLoader loader)
Gets the resource bundle for the given base name. |
protected java.lang.String |
getI18nString(java.util.ResourceBundle bundle,
java.lang.String baseName,
java.lang.String key)
Gets a string for the given key from the given resource bundle or one of its parents. |
javax.swing.JLabel |
getLabel(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JList |
getList(java.lang.String name)
Returns the component for the specified name. |
java.lang.ClassLoader |
getLoader()
Returns the class loader used to load components. |
java.util.Locale |
getLocale()
Returns the locale used to load resource bundles. |
javax.swing.JMenu |
getMenu(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JMenuBar |
getMenuBar(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JMenuItem |
getMenuItem(java.lang.String name)
Returns the component for the specified name. |
FormModel |
getModel()
Returns the form model. |
javax.swing.JPanel |
getPanel(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JPasswordField |
getPasswordField(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JPopupMenu |
getPopupMenu(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JProgressBar |
getProgressBar(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JRadioButton |
getRadioButton(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JRadioButtonMenuItem |
getRadioButtonMenuItem(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JScrollBar |
getScrollBar(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JScrollPane |
getScrollPane(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JSeparator |
getSeparator(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JSlider |
getSlider(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JSpinner |
getSpinner(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JSplitPane |
getSplitPane(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JTabbedPane |
getTabbedPane(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JTable |
getTable(java.lang.String name)
Returns the component for the specified name. |
java.lang.Object |
getTarget()
Returns the object that handles events. |
javax.swing.JTextArea |
getTextArea(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JTextField |
getTextField(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JTextPane |
getTextPane(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JToggleButton |
getToggleButton(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JToolBar |
getToolBar(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JTree |
getTree(java.lang.String name)
Returns the component for the specified name. |
javax.swing.JWindow |
getWindow(java.lang.String name)
Returns the component for the specified name. |
boolean |
isSetComponentNames()
Returns whether java.awt.Component.setName() will be invoked
on all components of the form. |
protected java.lang.Object |
newComponentInstance(java.lang.Class<?> beanClass,
java.lang.String compName)
Creates a new instance of the given bean class. |
void |
setSetComponentNames(boolean setComponentNames)
Sets whether java.awt.Component.setName() will be invoked
on all components of the form. |
void |
setTarget(java.lang.Object target)
Set the object that will handle events. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FormCreator(FormModel model)
FormCreator
for the specified form model.
model
- The form model, from which the components should be created.public FormCreator(FormModel model, java.lang.ClassLoader classLoader)
FormCreator
for the specified form model
using the specified class loader.
model
- The form model, from which the components should be created.classLoader
- The class loader used to load components.public FormCreator(FormModel model, java.util.Locale locale, java.lang.ClassLoader classLoader)
FormCreator
for the specified form model
using the specified locale and class loader.
model
- The form model, from which the components should be created.locale
- The locale used to load resource bundles.classLoader
- The class loader used to load components.Method Detail |
---|
public FormModel getModel()
public java.util.Locale getLocale()
public java.lang.ClassLoader getLoader()
public java.lang.Object getTarget()
public void setTarget(java.lang.Object target)
This object must have handler methods as specified in the form. E.g. if you've specified an actionPerformed() event for a JButton and set the handler method to "myButtonPressed", the target object must implement following method:
private void myButtonPressed() { // handler code }If you've set the "Pass parameters" flag to true for the event, you can get the listener parameters:
private void myButtonPressed(ActionEvent e) { // handler code }
public boolean isSetComponentNames()
java.awt.Component.setName()
will be invoked
on all components of the form. Default is false
.
public void setSetComponentNames(boolean setComponentNames)
java.awt.Component.setName()
will be invoked
on all components of the form.
public void createAll() throws java.lang.Exception
java.lang.Exception
public java.awt.Component create() throws java.lang.Exception
java.lang.Exception
public javax.swing.JPanel createPanel() throws java.lang.Exception
javax.swing.JPanel
.
Convenience method that invokes create()
and
casts the result to JPanel
.
java.lang.Exception
public javax.swing.JDialog createDialog(java.awt.Window owner) throws java.lang.Exception
javax.swing.JDialog
.
Convenience method that invokes createWindow(Window)
and
casts the result to JDialog
.
owner
- The window to act as owner; or null
.
java.lang.Exception
public java.awt.Window createWindow(java.awt.Window owner) throws java.lang.Exception
java.awt.Window
.
owner
- The window to act as owner; or null
.
java.lang.Exception
public java.awt.Component create(java.lang.String name) throws java.lang.Exception
name
- The name of the form component.
java.lang.Exception
public java.awt.Component create(java.lang.String name, java.awt.Window owner) throws java.lang.Exception
java.awt.Window
.
name
- The name of the form component.owner
- The window to act as owner; or null
.
java.lang.Exception
public java.lang.Object[] createBindings() throws java.lang.Exception
java.lang.Exception
public java.awt.Component getComponent(java.lang.String name) throws NoSuchComponentException
getComponent
in interface com.jformdesigner.runtime.ComponentProvider
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the name specifies a non-visual bean.public java.lang.Object getBean(java.lang.String name) throws NoSuchComponentException
name
- The name of the bean.
NoSuchComponentException
- If a bean with the specified name
does not exist or the bean is not created.public java.lang.Object getBean(java.lang.String name, boolean create) throws java.lang.Exception
getBean
in interface com.jformdesigner.runtime.BeanProvider
name
- The name of the bean.create
- If true, create the bean if necessary.
java.lang.Exception
public javax.swing.JButton getButton(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JButton
.public javax.swing.JCheckBox getCheckBox(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JCheckBox
.public javax.swing.JCheckBoxMenuItem getCheckBoxMenuItem(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JCheckBoxMenuItem
.public javax.swing.JComboBox getComboBox(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JComboBox
.public javax.swing.JDialog getDialog(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JDialog
.public javax.swing.JEditorPane getEditorPane(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JEditorPane
.public javax.swing.JFormattedTextField getFormattedTextField(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JFormattedTextField
.public javax.swing.JFrame getFrame(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JFrame
.public javax.swing.JLabel getLabel(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JLabel
.public javax.swing.JList getList(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JList
.public javax.swing.JMenu getMenu(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JMenu
.public javax.swing.JMenuBar getMenuBar(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JMenuBar
.public javax.swing.JMenuItem getMenuItem(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JMenuItem
.public javax.swing.JPanel getPanel(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JPanel
.public javax.swing.JPasswordField getPasswordField(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JPasswordField
.public javax.swing.JPopupMenu getPopupMenu(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JPopupMenu
.public javax.swing.JProgressBar getProgressBar(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JProgressBar
.public javax.swing.JRadioButton getRadioButton(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JRadioButton
.public javax.swing.JRadioButtonMenuItem getRadioButtonMenuItem(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JRadioButtonMenuItem
.public javax.swing.JScrollBar getScrollBar(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JScrollBar
.public javax.swing.JScrollPane getScrollPane(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JScrollPane
.public javax.swing.JSeparator getSeparator(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JSeparator
.public javax.swing.JSlider getSlider(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JSlider
.public javax.swing.JSpinner getSpinner(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JSpinner
.public javax.swing.JSplitPane getSplitPane(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JSplitPane
.public javax.swing.JTabbedPane getTabbedPane(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JTabbedPane
.public javax.swing.JTable getTable(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JTable
.public javax.swing.JTextArea getTextArea(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JTextArea
.public javax.swing.JTextField getTextField(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JTextField
.public javax.swing.JTextPane getTextPane(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JTextPane
.public javax.swing.JToggleButton getToggleButton(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JToggleButton
.public javax.swing.JToolBar getToolBar(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JToolBar
.public javax.swing.JTree getTree(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JTree
.public javax.swing.JWindow getWindow(java.lang.String name) throws NoSuchComponentException
name
- The name of the component.
NoSuchComponentException
- If a component with the specified name
does not exist or the component is not created.
java.lang.ClassCastException
- If the component is not a instance of JWindow
.protected java.lang.Object newComponentInstance(java.lang.Class<?> beanClass, java.lang.String compName) throws java.lang.Exception
return beanClass.newInstance();
".
Override this method to implement special component creation.
beanClass
- The component class.compName
- The name of the component.
java.lang.Exception
protected java.util.ResourceBundle getI18nBundle(java.lang.String baseName, java.util.Locale locale, java.lang.ClassLoader loader)
return ResourceBundle.getBundle(baseName, locale, loader);
".
Override this method to implement special bundle loading.
baseName
- The base name of the resource bundle, a fully qualified class name.locale
- The locale for which a resource bundle is desired.loader
- The class loader from which to load the resource bundle.
protected java.lang.String getI18nString(java.util.ResourceBundle bundle, java.lang.String baseName, java.lang.String key)
return bundle.getString(key);
".
Override this method to implement special string loading.
bundle
- The resource bundle to get the string from.baseName
- The base name of the resource bundle, a fully qualified class name.key
- The key for the desired string.
|
JFormDesigner 5.0.4 Runtime API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |