X

Geertjan's Blog

  • August 12, 2006

Programmatically Setting the Size of a NetBeans Platform Application

Geertjan Wielenga
Product Manager
The default size of NetBeans rich-client applications is "pretty massive". I'd be more specific and give an X value and a Y value, except that it isn't relevant anymore, because I now know how to change the default size. If you use the Module Installer wizard, the IDE generates a Java template (as well as the related dependencies) that you can use to specify what happens at start up (use the generated restored() method for that). So, here's the code (you need to create a listener, because the size is reset after the application is started):

public void restored() {
//Set the size of the initial screen to something manageable:
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Frame f = WindowManager.getDefault().getMainWindow();
f.addWindowListener(new Listener());
}
});
}
//Listener for setting size, because the size is reset after installation:
public class Listener extends WindowAdapter {
public void windowActivated(WindowEvent event) {
Frame f = WindowManager.getDefault().getMainWindow();
f.setSize(600, 400);
}
}

As a result, what you see above is exactly the new default size of the JFugue Music NotePad. Thanks to Stephen Kaspersen, from dev@openide.netbeans.org, for passing on this tip. (Anyone creating rich-client applications without regularly checking that list doesn't know what they're missing.)

By the way, as you might be able to see, the JFugue Music NotePad has made a lot of progress recently, which is really all thanks to Pierre Matthijs from Gent in Belgium. Now, there's a wizard for setting up a score (i.e., a music sheet). The coolest new thing is that when you reach the end of a stave, irrespective of the width of the application, a new one is immediately created below it. That's really a very cool improvement. But Pierre has generally rewritten the underlying architecture of the application so that it is a lot more robust and can be expanded with more functionality more easily from now onwards. A lot needs still to be done. The biggest issues right now are that you can't insert notes between existing notes and that the editor isn't synchronized with the new multi-document structure. But it has clearly come a long way already! Watch this space for further updates or join the project (with NetBeans IDE 5.5 Beta 2, you should just be able to check out the sources and run them without any problem at all). Check out the sources here.

Join the discussion

Comments ( 5 )
  • Pierre Saturday, August 12, 2006
    Geertjan,
    a tiny, little detail; I live in Zottegem, about 20 km south of Gent ;-)
  • Sandip Monday, August 14, 2006
    You should set the size in the -

    public void windowOpened(WindowEvent event) {
    }

    callback instead of -

    public void windowActivated(WindowEvent event) {
    }

    callback.
    Otherwise the window size will keep jumping back to the specified size even if the user resized the window to the size they prefer. This will happen every time the user clicks on some other window and then clicks back on the JFugue Music Notepad window (because the windowActivated() is called every time the window is (re)activated i.e. regains active status).

  • Geertjan Monday, October 16, 2006
    Thanks for this comment Sandip and apologies for the wrong place name, Pierre!
  • Brandon Goodin Monday, October 16, 2006
    Very useful information on resizing. I expanded on this a bit more on my site. I incorporated what Sandip suggested and added code to retain the state of the app when the user exits.
    Please see tutorial at:
    http://foldingreality.com/?q=node/2
  • Somnath Kavalase Tuesday, March 15, 2016

    Thank you Sandip Sir, for your valuable comment use of

    windowOpened(WindowEvent event){}

    method instead of using

    windowActivated(WindowActivated event){}

    It is useful if window will resize more than one time in application.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.