Geertjan's Blog

  • June 23, 2006

Free Semi-Colon with Code Completion in NetBeans Editor

Geertjan Wielenga
Product Manager
This is my current favorite "wow, cool" thing in the NetBeans editor. It's really small, but really cool. This is how it goes... Normally, when you (at least, I) use code completion, as in for example this scenario...

...you would click with the mouse, or press Enter, to complete the code. The result is then as follows:

In other words, you get the code you requested from the Code Completion box and the cursor lands in between the brackets.

However, if—instead of pressing Enter (or using the mouse click)—you press the semi-colon on your keyboard, you get this instead:

Hurray, a free semi-colon! (It also works with commas and periods, in the same way.) And the cursor still lands between the brackets! So you can start coding right away and you don't need to add a semi-colon afterwards.

It sounds like a really small thing, but it is really very powerful. If you look up page 98 of the 2nd edition of the NetBeans IDE Field Guide, you will find this code completion trick, as well as a few others. (In fact, the whole of chapter 5, about editing and refactoring in NetBeans IDE is very cool. Loads of little bits of information that you might not know about.)

And in other news, Wouter van Reeven, who I mentioned a few times in the last few blog entries, has begun blogging some very cool introductory topics on the OpenOffice.org API: Getting started with the OpenOffice.org API part I: connecting to OpenOffice.org and Getting started with the OpenOffice.org API part II : some basic Writer operations. These blog entries, and anything else he's going to be writing, are absolutely crucial if you're getting started with the OpenOffice.org API. And even if you're more advanced, there's bound to be info that you're not aware of that you'll find in Wouter's blogs.

Join the discussion

Comments ( 8 )
  • Michel Graciano Friday, June 23, 2006
    I testing this, and when I press semi-colon in keyboard, this works a little different, the cursor is moved after the semi-colon. I have config something? I am using last NB 5.5 qbuild.
  • Rory Friday, June 23, 2006

    Michel, the cursor will move to after the semi-colon if there aren't any arguments ;)
    What a cool tech tip for a friday.... thanks Geertjan.
  • Wouter van Reeven Friday, June 23, 2006
    Hey Geertjan, it even gets better with those semi-colons. Suppose you have a method that takes an int (or whatever, as long as it's not a String) as an argument. When you accidentically hit the Enter key instead of the semi-colon key, you still get the semi-colon BEHIND the method when you press the semi-colon.
    O and thanks for mentioning my blogs :-)
    Greets, Wouter
  • Michel Graciano Friday, June 23, 2006
    I tested with same example, the JOptionPane methods, and works as I describe before. I thought in that before too, but don't work for me. Any ideas?
    And Geertjan, greateee tip.
  • Chuck Davis Friday, June 23, 2006
    When are we going to get back our ability to hit ; in a String or between "" and get a jump to the end with the ; put in place? We used to have that function and now it is gone. I really miss it! Perhaps the new editor will bring it back? I filed an issue several months ago. It's really a pain to press "end" to place the semicolon when one is finished with a string. It's as bad as eclipse!
  • Surya Friday, June 23, 2006
    Very neat! Though it is quite a small thing but dead useful nonetheless!
  • Ed Burnette Saturday, June 24, 2006
    I wish somebody would put something like that in Eclipse. The missing semicolon has always annoyed me. I watched Ben Galbraith flying through IDEA once and I think it \*might\* be doing it right, but he was going so fast it was hard to tell.
  • Geertjan Saturday, June 24, 2006
    Hi all, good to know I'm not alone in seeing this as a valuable bit of functionality. For those (Chuck Davis and Michel Graciano) who have left comments about problems they've encountered: I'll try and talk to someone who knows and find out (please submit an issue to Issuezilla if one doesn't exist yet).
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.