Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you set some sort of custom code folding in Netbeans like in Visual Studio

When working on C#, I often do this:

#region Properties
  public int Property1{get;set;}
  ...(more properties)
#endregion

This makes Visual Studio add the option to fold the code inside the region. Offcourse, you can use regions for anything, it's not limited to Properties or anything at all.

I'm wondering 2 things:

  1. Is this just something to make Visual Studio add code folding to an area of the editor or does it affect the compiler?
  2. Can I do something similar in Netbeans?
like image 708
KdgDev Avatar asked Aug 09 '09 17:08

KdgDev


3 Answers

  1. (In Netbeans at least) It is purely a programmer aid and has no effect on compilation
  2. Yes you can

One caveat to the folding reference:

Please note that the above examples are for java language. In other languages custom folds may not be supported or you may have to use different characters for marking line comments.

like image 105
Rich Seller Avatar answered Oct 18 '22 22:10

Rich Seller


  1. It does not affect compilation, it's just to organise code in the editor. You can pick up on arguments on when best to use them in this question.
  2. In NetBeans you can use Custom Folds, depending on the language:

    // <editor-fold defaultstate="collapsed" desc="My Fold">
    Your amazing code
    // </editor-fold>

The attributes are optional. Without defaultstate specified the region will default to expand (except for when you first wrap code in it!)

like image 43
noelicus Avatar answered Oct 18 '22 22:10

noelicus


The latest Netbeans 8.1 has already this feature build in, You need just select you rows and then click on the "light bulb" icon, then select:

enter code hereSurround with // <editor-fold defaultstatus="collapsed" desc="comment">...

This is the source: http://wiki.netbeans.org/SurroundWithCodeFolding

like image 21
Pini Cheyni Avatar answered Oct 18 '22 22:10

Pini Cheyni