« Spam Honey Pot | Main | MS Word - VBA - StoryRanges - Odd-page headers »

September 18, 2006

Oracle Forms goodness - extending the text fields

I've gotten pretty frustrated with the Forms development environment, so I never thought I'd see the word "goodness" combined with "Oracle Forms", but recently I've made a breakthrough of sorts that has really encouraged me to pursue more elegent Forms programming.

Every Oracle Form is composed of Java objects. Text fields, buttons, frames, you name it, they are all some derivitive of Java awt or swing objects. As such, they can be extended.
Sounds simple, even too simple, doesn't it? Well, it really is!
If you're a Forms developer, there's a good chance that you know about embedding Java Beans (also called PJCs - Pluggable Java Components) into your Forms. They're really cool and can be used to accomplish all kinds of things. This takes PJCs one level further.

Let's assume that you have a text field to which you want to apply special effects. One of the most popular effects is to make the field behave like a hyperlink: blue in color, underlined, and, most importantly, having the mouse cursor change to the historical "hand".
Applying the color and underline are straightforward Forms development features, but the mouse cursor is another matter entirely. Ever since Forms became "webified", the ability to natively capture mouse-over events has disappeared because the traffic required for the server to track mouse movement is huge. However, PJCs run on the client, so we can employ them to implement mouse over effects. Oracle has provided a Hyperlink Bean in its demo package, but the drawback of the Hyperlink bean is that it takes too long to load, so having a decent number of them in a Form (say, 10 - 20) causes the Form load time to go through the roof.
However, if you write a class that extends the Forms text field, you can apply that class to select fields using the Implementation Class in the Properties Page, and the load time (so long as you don't do extravent things in the constructor) is the same as a regular text field.
Now, take that and apply it to ANY forms object. Write a class that extends the button object to implement "rollover" effects. Or how about extending text fields so that they scroll their text like a ticker tape? Or image objects that load new images every x seconds?

Anyway, here's one implementation I came up with. This text field extension underlines the text and does the following on mouseover: turns the cursor into a hand, makes the font bold, changes the font color to red, changes the background color to gray. You can easily add Property IDs to control the behavior. This concept and most of the code was taken from the Oracle demo ModCursor:

import java.awt.Graphics;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Font;
import oracle.forms.ui.VTextField;
import oracle.forms.properties.ID;
import oracle.forms.handler.IHandler;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Cursor;

public class Hotlink
extends VTextField

private Cursor stdCursor;

private Font stdFont;
private int stdStyle;

private Color stdForeColor;
private Color stdBackColor;

public Hotlink()

public void init(IHandler h)

stdCursor = this.getCursor();

this.addMouseListener(new MouseAdapter()
public void mouseEntered(MouseEvent me)
if(getTextLength() > 0)
setCursor(new Cursor(Cursor.HAND_CURSOR));
public void mouseExited(MouseEvent me)
if(getTextLength() > 0)

public void paint(Graphics g)
if (this.getTextLength() > 0)
FontMetrics metrics = getFontMetrics(getFont());
int strWidth = metrics.stringWidth(getText());
int yoffset = (int)(metrics.getHeight() * 0.95);
g.drawLine(0, yoffset, strWidth, yoffset);

public boolean setProperty(ID pid, Object value)
if(pid.getName().equals("FOREGROUND")) this.stdForeColor = (Color)value;
else if(pid.getName().equals("BACKGROUND")) this.stdBackColor = (Color)value;
else if(pid.getName().equals("FONT")) this.stdFont = (Font)value;
return super.setProperty(pid, value);

Posted by Peter at September 18, 2006 10:03 AM


Hey this really helped me to extend a VButton in Oracle Forms. Thanks for the heads up!!!!!

Posted by: Joe at July 24, 2007 10:20 AM

Its really a nice program and i am unable to use this in Oracle Forms. Can you please explain how to use the same in Oracle Forms.

Posted by: Balaji at March 26, 2008 04:52 AM

Just found your article about JPC and Oracle Forms.
Any idea if it is possible to impelemt a text item with vertical text using JPC?
thanks a lot for any reply...

Posted by: Heiko at June 3, 2008 12:23 AM

Post a comment

Remember Me?