taT | Editor Fold Utility

Hey,

Another tips and Tricks for today! Whenever you have created a JFrame in NetBeans, the auto-generated code which is in sync with Matisse Builder, has a method initComponents() initially, right?

When you make a switch to the Source view, you see a collapsed section of code, with a label on it- “Generated Code”. Ever thought, how it happens.

Here’s the trick

Write code between following comments;

        //<editor-fold defaultstate="$state" desc="$label">
        /* Place your code over here */
        //</editor-fold>

Replace $state with expanded/collapsed and $label with any name/phrase you choose. Also, replace the following;

        /* Place your code over here */

with your code, it could be either inside a method, or inside a Java class, wrapping various methods, variable declarations etc.

Tips to Remember

Keep in mind that, the editor-fold tags must be inside same block of code, either inside a Java class, or inside a method! You can’t opening tag inside a Java class, and closing tag inside a method OR vice-versa!

It works in all Java classes. Also, its basic use is to categorize the sections of code. Like, you may have an editor-fold for only variable declarations, and/or for user created methods, and/or for getter/setter methods!

eNjoy Technology…

3 thoughts on “taT | Editor Fold Utility

  1. Your posts to Planet Netbeans are not working correctly. When I click on your posts, I am sent to the most recent post in the stack stack of posts instead of opening your post.

    All other posts work as expected. Please fix this problem.

  2. Pingback: 10 Tips and Tricks « N, Varun

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s