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.
Comments (7)