« [Commentary] Try Servoy out on your new iPhone | Main | [Tip] Method as a function and as a method »
July 06, 2007
Using the JInternalFrame Bean
by Scott Butler
Servoy
So today I had a customer email me, asking about the JInternalFrame, and what it was used for. I hadn't played around with that bean in Servoy yet, so I decided to see what cool things could be done with it....and actually, I was pretty impressed. Essentially, you can created floating windows within the Servoy application. I've included some example code with screenshot for a very basic example...but I'm sure you guys can expand on the example to do some really cool stuff.
Start by creating a blank form, and add 2 JInternalFrame beans to the form. Name the first one bean_JInternalFrame and the second one bean_JInternalFrame2. Size them however you want.
Next, lets create some methods. First a generic method that will create a new label object to be placed in our JInternalFrame bean. In my example, I called this method sub_getLabel
var text = arguments[0]
var color = arguments[1]
var myNewJLabel = new Packages.javax.swing.JLabel(text)
myNewJLabel.setVerticalAlignment(Packages.javax.swing.JLabel.TOP);
myNewJLabel.setHorizontalAlignment(Packages.javax.swing.JLabel.CENTER);
myNewJLabel.setOpaque(true);
myNewJLabel.setBackground(color);
myNewJLabel.setForeground(Packages.java.awt.Color.black);
var myBorder = Packages.javax.swing.BorderFactory.createLineBorder(Packages.java.awt.Color.black)
myNewJLabel.setBorder(myBorder);
var myNewOriginPoint = new Packages.java.awt.Point(10, 20);
myNewJLabel.setBounds(myNewOriginPoint.x, myNewOriginPoint.y, 140, 140);
return myNewJLabel
Next, create this new method, and add it to the onLoad event on the form.
//setup the first JInternalFrame
var myLayeredPane = elements.bean_JInternalFrame.layeredPane
var myNewJLabel = sub_getLabel("myTitle1", Packages.java.awt.Color.yellow);
myLayeredPane.add(myNewJLabel)
elements.bean_JInternalFrame.visible = true
//setup the second JInternalFrame
var myLayeredPane = elements.bean_JInternalFrame2.layeredPane
var myNewJLabel = sub_getLabel("myTitle2", Packages.java.awt.Color.red);
myLayeredPane.add(myNewJLabel)
elements.bean_JInternalFrame2.visible = true
Now, its time to test your new form with the 2 JInternalFrame beans! If all goes well, you should see something that looks like the screenshot below. The user can drag each floating window around inside of their Servoy application. In our example, I just added a label to the JInternalFrame, but you can obviously add a lot more..fields, buttons, images, etc. In addition, the floating windows are non-modal. So, the user can just have them siting to the side while they continue to interact with the application.
| Posted by Scott Butler on July 6, 2007 at 02:49 PM in Tips | Permalink
Comments
Our DialogPro-Plugin (www.servoy-plugins.de) allows you to do the same, but does not require you to get into Java coding. All the layouting is done by the Plugin and instead of "var myNewJLabel = new Packages.javax.swing.JLabel(text) etc." you can simply use something like "myDialog.addLabel(text)".
Posted by: | Jul 9, 2007 4:17:38 AM
Iconable Property of JInternalFrame Bean is not working properly.
According to the Iconable Property of JInternal Frame, when a user clicks on it it will shrunk down and displayed as an icon-image in the left bottom.
But it is deviating from the usual.
It is not shrinking down.
Posted by: ars | Jul 10, 2007 9:37:49 AM
From my tests Iconable Property is working correctly. Just add the following code before you set visibility=true...
elements.bean_JInternalFrame2.iconifiable = true
Then when the user clicks, it will minimize in the bottom left of the application window. However, you need to make a call to the bean to update UI (or just resize the application) and it will refresh.
elements.bean_JInternalFrame2.updateUI()
Then you will see a thumbnail of the frame in the bottom left, and when you roll over it will see the name of the JInternalFrame.
Posted by: Scott Butler | Jul 10, 2007 10:26:25 AM
Thanks Scott
Posted by: | Jul 11, 2007 12:27:33 AM
Hi Scott,
It is not working.
Here is the code snippet.
*************************************
elements.JInternalFrame1.iconifiable = true;
elements.JInternalFrame1.updateUI();
elements.JInternalFrame1.visible = true;
*************************************
I am not getting what is going wrong.
Posted by: ars | Jul 11, 2007 12:48:50 AM
First you must set the iconifable property to true, this just tells it that it can be minimized.
elements.bean_JInternalFrame2.iconifiable = true
//then set it to visible
Next, after the user has minimized the JInternalFrame, you have to call
elements.bean_JInternalFrame2.updateUI()
Otherwise it will look as if the JInternalFrame has disappeared.
Posted by: Scott Butler | Jul 11, 2007 8:34:53 AM
Anyone aware of how to make the internal non movable/not dragable?
Posted by: Jeff Bader | Sep 13, 2007 9:18:42 AM
