Dark theme | Light theme

July 2, 2009

Generate code with code completion in NetBeans

The code completion for Java in NetBeans 6.7 also includes options for code to be generated. In previous versions we had to use Source | Insert Code..., but now we only have to press Ctrl+Space and we get to see which code can be generated by NetBeans.

Suppose we have the followings simple class:

package javaapplication11;

public class MyObject {
    private String netbeansRules;

We press Ctrl+Space (in Windows) to activate code completion (or select Source | Complete Code.... NetBeans shows the code completion popup:

At the top we see the code NetBeans can generate for us. We see constructors, methods to override from java.lang.Object and get/set methods for our property:

We select the option we want to let NetBeans generate the code.