Geertjan's Blog

  • September 12, 2011

Alt-Enter in Code Completion Box

Geertjan Wielenga
Product Manager
Let's say you have this class:
public class Customer {
String type;
public Customer() {
public String getType() {
return type;
public void setType(String type) {
this.type = type;

Now, somewhere else in your application, you need to work with the Customer object.

So, you create and initialize a new Customer, somewhere, and then later you want to call the getter on the customer. So you call up code completion (Ctrl-Space):

Now, here are three different keys that you can press when you're exactly at the place shown above in the code completion box, together with the result when you do so:

  • Enter:

  • Semicolon:

  • Alt-Enter:

    String type = c.getType();

The latter, Alt-Enter, is new  in the upcoming NetBeans IDE 7.1, created by NetBeans engineer Dusan Balek, based on an issue by Tom Wheeler. When you use Alt-Enter, the entire statement is generated (i.e., the method is selected and the assignment is done and the semicolon is created), while the cursor ends up on the name (e.g., "type" above) so that you can immediately change it if needed, before continuing with your coding.

Cool, isn't it?

Join the discussion

Comments ( 5 )
  • guest Monday, September 12, 2011

    Cool indeed!

    Don't forget

    - dot (".") for:


  • ranjan Tuesday, September 13, 2011

    this looks really good, I will remember this ,thanks to Dusan and you.

  • Tom Wheeler Tuesday, September 13, 2011

    Another issue I filed is now implemented for NetBeans 7.1:


    This adds a transpose feature to the editor, so when you type something like this:

    Person geertjan = new Preson();

    You can now just put your cursor between the 'r' and 'e' in the misspelled class name and hit Ctrl-T to fix it, just like you can in emacs or the bash shell.

    Thanks to Miloslav Metelka and Dusan Balek for implementing these helpful features.

  • Carlos Eduardo Klock Sunday, September 18, 2011

    I would like to see that as the default behaviour when you press Enter. Why not?

    When you press Enter in Code Completion Box one of these should happen:

    - Generate the entire statement.


    - Complete the code and add ';' at the end.

    I can't imagine a good reason not to do this by default when Enter is pressed. If you do not want to create the entire statement then you press '.', ';' or space.

  • guest Friday, September 23, 2011

    Alt-Enter in Code Completion Box is an excelent feature. I tested now in NetBeans 7.1 Beta. It seems 7.1 is faster, but maybe is only a first impression...

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