creating a child window

36 views
Skip to first unread message

Ian Martins

unread,
Jun 3, 2010, 10:04:49 AM6/3/10
to SDL/Swing
Is it possible for an sdl app to create a child window that contains a
menu? I can create a child window using UI.startApplication() but I
can't get a reference to the child window's controller object. I
haven't been able to create a window with a menu using UI.build().

-Ian

Dan Leuck

unread,
Jun 3, 2010, 2:11:17 PM6/3/10
to sdls...@googlegroups.com
Hi Ian,

I just tested creating a secondary window with a menu using UI.build(String);

SDL: myFrame.sdl

frame {
menus {
"Greetings" {
"Greet" do="hello"
}
}
form ID="MyFrame" {

}
}

Java: MyFrameController.java

public class MyFrameController extends FormController {
public void hello() {
System.out.println("Hello");
}
}

From within the AppController call:

JFrame frame = (JFrame)UI.build("myFrame");
frame.setVisible(true);

The menu will automatically be wired to the form controller associated
with the form set on the frame's content pane (i.e. MyFrame.) This is
the same special handling of menus and forms you see with
UI.startApplication();

If you need a reference to the controller and you have only the frame
that contains its form call:

MyFrameController controller =
(MyFrameController)((Form)frame.getContentPane()).getController();

The next release of SDL/Swing will make this easier by adding a
getTopLevelController() method to the frame.

Does this answer all your questions?

Dan

Ian Martins

unread,
Jun 3, 2010, 2:30:29 PM6/3/10
to sdls...@googlegroups.com
thanks, that worked.

I was trying to use UI.getFormForComponent(frame) instead of
frame.getContentPane() in order to get the Form object.

Ian Martins

unread,
Jun 3, 2010, 3:54:36 PM6/3/10
to sdls...@googlegroups.com
Two things I've noticed. pack() must be called before setVisible() to
set the frame's initial size. Also, it doesn't look like shown() is
being called on MyFrameController, but its easy enough to call it after
getting the controller reference.

On 06/03/2010 02:11 PM, Dan Leuck wrote:

Dan Leuck

unread,
Jun 3, 2010, 4:51:04 PM6/3/10
to sdls...@googlegroups.com
> Two things I've noticed.  pack() must be called before setVisible() to set
> the frame's initial size.

Yes. That is true for windows in general. You either have to call
pack() or manually set their bounds before calling setVisible(true);

>  Also, it doesn't look like shown() is being
> called on MyFrameController, but its easy enough to call it after getting
> the controller reference.

You are right. That is a bug that affects frames other than the main
application frame. We'll have it fixed for the next release. In the
meantime, as you indicated, you can just call it on the controller.

Best,
Dan

Dan Leuck

unread,
Jun 12, 2010, 8:37:57 PM6/12/10
to SDL/Swing
Ian - the shown() bug you mentioned has been fixed in the 1.0 release.
Also, the API has been enhanced so you can call:

MyFrameController controller =
(MyFrameController)frame.getForm().getController();

...to get the controller from a com.ooi.swing.Frame (this is what is
created by the "frame" tag.)

Best,
Dan
Reply all
Reply to author
Forward
0 new messages