A script-enabled browser is required for this page to function properly.

How to Add Custom User Interface Components with PJCs

There are several ways you can customize your user interface using Pluggable Java Components (PJCs):

Each type of customization has its own steps, described below.

Note: You can use any code editor to create the Java classes, but to speed your code development, use Oracle JDeveloper. JDeveloper contains a Pluggable Java Components Wizard that can access all Forms component classes. Use the wizard to choose the class of the Forms component that you want to customize, and JDeveloper generates the skeleton code that extends the IView interface. All you have to do is add your own code to the file that defines the functionality you want, and include the file in your Forms codebase. For more information on the Pluggable Java Components Wizard, see the JDeveloper Online help.

To extend an existing Forms class:

  1. Create your own implementation by extending one of the existing Forms-supplied user interface classes, which thus creates your own new class. (The Forms-supplied classes are listed below.)
  2. If needed, override setProperty() and/or getProperty() methods to handle properties.
  3. Store your class in the Forms codebase.
  4. Identify your class in the Implementation Class property of the user interface item in your Form.

To extend a non-Forms class

  1. Create a new class by extending some other class, but have it implement the IView interface (the class to be extended could be a class from the JFL or a third-party class).
  2. Include getProperty() and setProperty() methods. These must handle the properties that Forms specifies normally for that class of user-interface item.
  3. Store the class in the Forms codebase.
  4. Identify the class in the Implementation Class property of the user interface item in your Form.

To create a container class

  1. Create a container class that implements the IView interface.
  2. Create your new user-interface element within this container.
  3. Write your own getProperty and setProperty methods to handle the properties, such that the appropriate methods on the component are invoked.
  4. Make sure that listeners are added to the user interface component to monitor end-user actions on the interface component.
  5. Identify the class in the Implementation Class property of the user interface item in your Form.

To create a new type of interface element

  1. Create your own class for the new element type.
  2. Have the new class implement the IView interface.
  3. Implement whatever methods the class requires.
  4. Identify the class in the Implementation Class property of the user interface item in your Form.

Forms-supplied classes for user interface items

The Forms-supplied class definitions for user interface components are:

Oracle Look and Feel

To obtain the appearance of interface components offered by the Oracle Look and Feel (for example, rounded buttons), add <param name = "LookAndFeel" value = "Oracle"> and <param name = "LookAndFeel" value = "ColorScheme"> to the HTML file.

Adding Custom User Interface Components: Examples

Example 1: Extending an Existing Forms Class

 
 import oracle.forms.ui.VButton;
 import oracle.ewt.button.PushButton;
 public class SingleButton extends VButton 
 {
     public SingleButton()
     {
         super(); 
         setLeftmost(true);
         setRightmost(true);
     }
 }

Example 2: Creating a New Class by Extending a Different Class

 
 package oracle.forms.jfcplug;
 import com.sun.java.swing.*;
 import com.sun.java.swing.border.*;
 import com.sun.java.swing.event.*;
 import java.awt.*;
 import java.awt.event.*;
 import java.util.EventListener;
 import oracle.forms.handler.IHandler;
 import oracle.forms.properties.ID;
 import oracle.forms.ui.IView;
 public class       VJCheckBox
        extends     JCheckBox
        implements  IView
 {
     /* Instance counter used to generate default names */
     private static int   sInstanceCounter;
     /* Helper class to handle the IView interface */
     private IHandler     mHandler;
     private int          mInstance;
     /**
     ** Constructs a new JCheckBox.
     */
     public VJCheckBox()
     {
         super();
         mInstance = sInstanceCounter++;
     }
     /**
     ** Implementation of IView interface
     **
     ** @param handler - message handler associated with this view.
     ** @see IView
     */
     public void init(IHandler handler)
     {
         mHandler = handler;
     }
     /**
     ** Implementation of IView interface
     **
     ** @see IView
     */
     public void destroy()
     {
     }
     /**
     ** Implementation of IView interface
     **
     ** @param id - property id
     ** @return the value of the property id
     ** @see IView
     */
     public Object getProperty(ID id)
     {
         switch  ( id.toID() )
         {
            case ID.INDEX_BOUNDS:
                return getBounds();
            case ID.INDEX_ENABLED:
                return isEnabled() ? Boolean.TRUE : Boolean.FALSE;
            case ID.INDEX_LANGUAGE_DIRECTION:
                return mDirection;
            case ID.INDEX_LOCATION:
                return getLocation();
            case ID.INDEX_SIZE:
                return getSize();
            case ID.INDEX_VISIBLE:
                return isVisible() ? Boolean.TRUE : Boolean.FALSE;
            case ID.INDEX_UI_PARENT:
                return getParent();
             case ID.INDEX_LABEL:
                 return getText();
             case ID.INDEX_VALUE:
                 return isSelected() ? Boolean.TRUE : Boolean.FALSE;
             default:
                 return null;
         }
     }
     /**
     ** Implementation of IView interface
     **
     ** @param id    - property to be set.
     ** @param value - value of the property id.
     ** @return      - true(if the property could be set), false otherwise.
     ** @see IView
     */
     public boolean setProperty(ID id, Object value)
     {
         switch  ( id.toID() )
         {
             case ID.INDEX_BACKGROUND:
                Color bgColor = (Color) value;
                setBackground(bgColor);
                return true;
             case ID.INDEX_ENABLED:
                setEnabled(toBoolean(value));
                return true;
             case ID.INDEX_FOCUS:
                // Only settable to true:-)
                if ( value == Boolean.TRUE )
                {
                    cp.requestFocus();
                }
                return true;
             case ID.INDEX_FONT:
                setFont((Font) value);
                return true;
             case ID.INDEX_FOREGROUND:
                Color fgColor = (Color) value;
                setForeground(fgColor);
                return true;
             case ID.INDEX_LANGUAGE_DIRECTION:
                // Adjust the alignment to conform to the new lang direction
                // setDirection((LanguageDirection)value);
                return true;
             case ID.INDEX_LOCATION:
                setLocation((Point) value);
                return true;
             case ID.INDEX_SIZE:
                Point pt = (Point) value;
                setSize(pt.x, pt.y);
                return true;
             case ID.INDEX_VISIBLE:
                setVisible(((Boolean)value).booleanValue());
                return true;
             case ID.INDEX_LABEL:
                 setText((String)value);
                 return true;
             case ID.INDEX_VALUE:
                 setSelected(((Boolean)value).booleanValue());
                 return true;
             default:
                 return false;
         }
     }
     /**
     ** Implementation of IView interface
     **
     ** @param type     - Class type of the listener.
     ** @param listener - Listener object.
     ** @see IView
     */
     public void addListener(Class type, EventListener listener)
     {
         if ( type == FocusListener.class )
         {
             addFocusListener((FocusListener) listener);
         }
         else if ( type == KeyListener.class )
         {
             addKeyListener((KeyListener) listener);
         }
         else if ( type == MouseListener.class )
         {
             addMouseListener((MouseListener) listener);
         }
         else if ( type == MouseMotionListener.class )
         {
             addMouseMotionListener((MouseMotionListener) listener);
         }
         else if ( type == ItemListener.class )
         {
             addItemListener((ItemListener) listener);
         }
     }
     /**
     ** Implementation of IView interface
     **
     ** @param type     - Class type of the listener.
     ** @param listener - Listener object.
     ** @see IView
     */
     public void removeListener(Class type, EventListener listener)
     {
         if ( type == FocusListener.class )
         {
             removeFocusListener((FocusListener) listener);
         }
         else if ( type == KeyListener.class )
         {
             removeKeyListener((KeyListener) listener);
         }
         else if ( type == MouseListener.class )
         {
             removeMouseListener((MouseListener) listener);
         }
         else if ( type == MouseMotionListener.class )
         {
             removeMouseMotionListener((MouseMotionListener) listener);
         }
         else if ( type == ItemListener.class )
         {
             removeItemListener((ItemListener) listener);
             return;
         }
     }
     /**
     ** Implementation of IView interface
     **
     ** @param child - Object to be added( or inserted in Lists, Choice)
     ** @param index - The position of insertion. For add's, this is -1.
     ** @see IView
     */
     public void add(Object child, int index)
     {
         // Not supported
     }
     /**
     ** Implementation of IView interface
     **
     ** @child -  Element to be deleted from the list.
     ** @see IView 
     */
     public void remove(Object child) 
     {
         // Not supported 
     }
     /**
     ** Implementation of IView interface
     */
    public void removeAll()
     {
         // Not supported
     }
     /**
     ** Implement getDefaultName() to return a default name of
     ** the form <ClassName># where # is the instance number
     ** of the CheckBox
     */
     protected String getDefaultName()
     {
         return getClass().getName() + mInstance;
     }
 }

Extending Your Application with Pluggable Java Components

Item Type Property

Implementation Class