using JDesktopPane inside a Servoy solution

Hi all,

I’ve been playing around with JDesktopPane and JInternalFrame a bit, in an attempt to create something like a MDI or “IDE style interface” in the smart client. This is a bit like the “non modal window” feature that was recently added to Servoy, but then with an “internal desktop” that holds the windows, instead of having them just float around the application.

The good new is, it works. :wink: I can put a JSplitPane on my main form and then programmatically add a JDesktopPane to one of the 2 panes, and use the other pane for navigation purposes. I can then add as many JInternalFrames to de JDesktopPane as i want.

The bad news: you cannot ‘just’ put a Servoy form inside a JInternalFrame. You need to create a tabpanel that contains the form and then add that tabpanel to the JInternalFrame. This is where the problem starts. There is a way to create a new instance of a form now, but afaik there is no way to programmatically create a new instance of a tabpanel. This means that you cannot add a new form instance to a JInternalFrame or any other swing object.

As a workaround, i created a ‘dummy’ form that only contains an empty tabless tabpanel. Each time the user opens a new window, two new form instances are created: one instance of the form that the user requests and one instance of the ‘dummy’ form. The ‘real’ form then gets added to the tabless tabpanel on the dummy form, after which the tabpanel is added to the JInternalFrame.

Apart from the fact that this is quite a ‘dirty’ workaround that probably causes a lot of unnecessary overhead, this solution seems to have one major problem: Servoy doesn’t seem to update the UI for forms that it ‘thinks’ aren’t displayed at the moment. So, the only way make the form visible inside its new window, is to first do a controller.show() on the dummy form and then again a controller.show() on the main form that contains the JDesktopPane. Every time a script does something that changes anything on a form, like updating a value, you need to repeat these two steps to make the change visible on the form inside the JInternalFrame.

My question is: is there a better way to do this? Is there a better way to add a new servoy form instance to a swing object? Or is there anything i can do to get Servoy to update the UI without having to do the show() trick?

BTW, if anyone’s interested in a sample solution that does what i described above, let me know!

regards

Sander

I can put a JSplitPane on my main form and then programmatically add a JDesktopPane to one of the 2 panes

Out of curiosity, how are you adding the JDesktopPane? Last time I checked Servoy was not including the JDesktopPane bean with the distro. Have you added the bean yourself? If so, where did you find it?

new Packages.javax.swing.JDesktopPane() ???

I started down this path as well…Here is a related thread: http://forum.servoy.com/viewtopic.php?t … e0e7bfb752

jbader:

I can put a JSplitPane on my main form and then programmatically add a JDesktopPane to one of the 2 panes

Out of curiosity, how are you adding the JDesktopPane? Last time I checked Servoy was not including the JDesktopPane bean with the distro. Have you added the bean yourself? If so, where did you find it?

new Packages.javax.swing.JDesktopPane() ???

I started down this path as well…Here is a related thread: http://forum.servoy.com/viewtopic.php?t … e0e7bfb752

The JDesktopPane is not in the Bean list that Servoy provides, but as it’s a standard Swing component, there’s nothing that stops you from adding it from a script, as long as you have a container to add it to. I used a JSplitPane because i needed a navigation pane on the left of my screen anyway.

So, I added a JSplitPane to my main form through the Servoy interface, and then from a method that’s connected to the ‘onLoad’ event of the main form, i did:

globals.desktop = new JDesktopPane();
elements.mainSplitPane.rightComponent = globals.desktop;

That’s it. I’ve made a global variable that holds the desktop object, so that it’s easy to add new JInternalFrame’s from anywhere in the solution.

If you like i can make a small Servoy solution that shows how this works…

Oele:
globals.desktop = new JDesktopPane();

Off course, this should be Packages.javax.swing.JDesktopPane.

If you assign the JDesktopPane to a global, how are you adding JInternalFrames?

For me global_variable.add(JInternalFrame) doesn’t work, and complains that add is not a function. But if I do var foo = new JDesktopPane() foo.add(JInternalFrame) everything works just fine.

jbader:
If you assign the JDesktopPane to a global, how are you adding JInternalFrames?

For me global_variable.add(JInternalFrame) doesn’t work, and complains that add is not a function. But if I do var foo = new JDesktopPane() foo.add(JInternalFrame) everything works just fine.

var window = new Packages.javax.swing.JInternalFrame();
window.setSize(800, 800);
window.setVisible(true);
globals.desktop.add(window);

Are you sure that you defined the global variable with type MEDIA?

Oops, I set it as text :oops: :oops:

Problem is that a JInternalFrame() is not text… :wink: