Geertjan's Blog

  • September 17, 2007

Never Eat The Yellow Snow

Geertjan Wielenga
Product Manager
My IDE is even more helpful than before, now. Because I've been playing with the IDE's JGlassPane (as a result of some questions about this), I am now ready for winter:

Don't say I didn't warn you. I have found Chet and Romain's book very helpful in this instance too. Somewhere I read that their book is supposedly aimed at advanced Swing developers. Well, if that's true, why is there a detailed section on Threading (amongst several other interesting intro topics) at the start of the book? And not just a paragraph or two, but really in detail. Anyway, read page 34 of their book, create a module installer (helpful wizard generates practically everything you need) and then fill out the restored() method as follows:

private MyGlassPane glassPane = new MyGlassPane();
public void restored() {new Thread(new Runnable() {
public void run() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {

final JFrame mainWin = (JFrame) WindowManager.getDefault().getMainWindow();


The highlighted lines above come directly from the book, for posting nonblocking new tasks to the EDT. The bit in between the highlighted lines is... me grabbing the IDE's main window. And, from there, you can get the menu bar, the content pane, and, as in this case, the glass pane. Here, a TopComponent (yes! that tiny JTextField comes from a TopComponent) is set as the glass pane, with setOpaque(false) in its constructor, and, as you can see above, the typical call to setVisible on the glass pane. And, what does the TopComponent contain? Nothing but a JTextField, in the bottom right hand corner. So the TopComponent ends up being placed transparently over the surface of the IDE, with the JTextField fitting snugly into the bottom right corner.

And, remember, never eat the yellow snow.

In other news. I've been very slow in responding to several people over the last few days. I apologize! It's been a busy time in NetBeans land, what with the release of NetBeans IDE 6.0 Beta 1, and all the related loose ends that needed to be tied in the world of documentation (which is where I live). I hope to catch up with my correspondence in the next few days.

Join the discussion

Comments ( 5 )
  • Fabrizio Giudici Tuesday, September 18, 2007

    Wonderful. Can you clarify: is the TopComponent automatically grown to span the whole IDE room?

  • Geertjan Tuesday, September 18, 2007

    Hi Fabrizio, yes, AFAIK, that's what happens. If you do not change the default size of the TopComponent (or JPanel), then the whole span of the IDE is covered. If you change the default, via setSize() on the component, then a smaller area is used. That's my understanding of this, based on my own experiments.

  • David Strupl Wednesday, September 19, 2007

    Please don't tell people to do this from ModuleInstall.restored(). It is rather dangerous to access the main window from there. It is run when the splash screen is showing. By accessing the main window too early something might not be ready (yet). This is very risky approach - use WarmUp task or simple action to activate it.

    2nd thing is that I am not really sure whether putting your own glasspane is generally safe when using the NB main window. Maybe yes because e.g. the TopComponent DnD uses different glass pane for rendering the boxes but I would not be that sure that it is not the one from the main window. Does DnDping of TC work for you after this?

    And the last thing: why is there the new Thread created? SwingUtilities.invokeLater should be fine if the whole thing is launched at proper time. Postponing the call by unknown amount of time does not help anything - or to use better wording does not always help.

  • Fabrizio Giudici Wednesday, September 19, 2007

    WarmUp? Ok, looks like I'm learning some new stuff :-)


    But it says:

    + "don't rely on that the warm-up task is always run (execution is not guaranteed),"

    + "try to avoid manipulation with live AWT/Swing components requiring to post something to AWT event queue thread"

  • Geertjan Wednesday, September 19, 2007

    Hi David, thanks a lot for this info. I've learned a lot from it. I also didn't know about WarmUp tasks.

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