Visual Casts

So you can access the layout property of your container, and you know it's a java.awt.CardLayout, and you want to use it's next() method via a button press...

Problem is, layout is of type java.awt.LayoutManager; the Visual Composition Editor won't give you access to the methods defined in java.awt.CardLayout...

There's a trick lurking here...

VisualAge provides a really nifty feature called property-to-property connections.   These are very useful, as they do the following:

VisualAge has a nifty way of setting up property-to-property connections called "Tear-Off Properties".  If you bring up the pop-up menu for a bean in the Visual Composition Editor design area and select "Tear-Off Property," it will give you a list of all properties for the bean.  Select the one you want to tear off (in our example, layout).

This creates a new variable on the design area that is connected to the source bean via a property-to-property connection.  We can access the layout of the bean using this variable.

Next, change the type of the variable.  Select "Change type" from the pop-up of the variable you created during the tear-off.   For the new type, type in java.awt.CardLayout.

VisualAge will warn you that this might cause problems.  What it's really saying is that you are viewing the property as a different type, and therefore might get a ClassCastException if you're not careful.  If you know for sure that the property will cast properly, continue with it!

In our example, because we had set the layout to java.awt.CardLayout we know this will be fine...

Now, you can use that variable to access the next() method!  You have just performed a cast completely within the Visual Composition Editor!