Loading...

May 12, 2009

Quickly insert constructors from super class in NetBeans

To quickly insert constructors from a super class in NetBeans we only have to place the cursor in our class and go to Source | Insert Code... (or press Alt+Insert in Windows). For example we create a new Exception class for our application extending the java.lang.Exception class:

package com.mrhaki.netbeans;

public class AppException extends Exception {
    
}

NetBeans shows a pop-up window and we select Constructor....

We get a dialog window with all constructors from the java.lang.Exception class. We select the constructors we want and click on the Generate button.

Now our source code looks like this:

package com.mrhaki.netbeans;

public class AppException extends Exception {

    public AppException(Throwable cause) {
        super(cause);
    }

    public AppException(String message, Throwable cause) {
        super(message, cause);
    }

    public AppException(String message) {
        super(message);
    }

    public AppException() {
    }
    
}