Re: [Java-gnome-developer] how to build reusable components with glade
Brought to you by:
afcowie
From: Nicholas R. <ni...@mn...> - 2005-05-30 08:04:02
|
Hi, I have reusable glade components in my java-gnome application. for example, if you have a Frame (or an HBox or whatever widget) and want to reuse that widget in several places in your application, you can get an instance of that widget using the following code: try { myframe_glade = new LibGlade( getClass(). getResourceAsStream( "/myapp.glade" ), this, "my_reusable_frame" ); } catch ( Exception e ) { e.printStackTrace(); } What this does is create a new LibGlade instance that starts at the "my_reusable_frame" widget node in the glade XML file "myapp.glade" (NOTE: that i'm loading the glade XML file as a resource (from within a JAR file actually), but you could just pass a file name (String) as the first parameter too.) You can then call: (Frame)myframe_glade.getWidget( "my_reusable_frame" ) to get that Frame instance. You can also get any widgets that are defined as sub-widget nodes of "my_reusable_frame" by calling myframe_glade.getWidget( "widget_in_my_reusable_frame" ). The downside of this is that you're parsing your glade file once for each LibGlade object you create. In practice i've found that libglade parses the XML file very quickly and that this does not really slow things down, but perhaps my glade file is not that big. :-) Also you do have multiple LibGlade objects lying around. You'll probably want to have a class (MyReusableFrame) that includes myframe_glade as one of it's members (calling the above code in the constructor, for example) and then instantiate this class whenever/wherever you need that frame. Hope this helps, Nick On Sat, 2005-05-28 at 21:16 +0200, Tomasz Mielnik wrote: > Hi > I'm still lerning java-gnome together with glade capabilities so i > encountered a issue that I can't solve. > > Is there w way to build a window inside glade editor ant then use this > window as my own widget inside other windows (ie; in other VBox)? > Or how can I achieve this functionality with java-gnome/glade? > > In SWT for instance there this concept of Shells Where toplevel window > is a shell and any container is a Shell including top level window in > another container is straightforward. > > Any help as always is appreciated. > |