Reputation: 69259
Is it possible in Netbeans to hide some pieces of code, especially debugging code, from the Source Code View?
For example I would want to hide: System.out.println("DEBUG: ...");
, with ...
being whatever is needed to print some variables.
I don't like that it misses up how my code looks, but if I remove it entirely then I might need it again tomorrow for example.
Upvotes: 1
Views: 4527
Reputation: 146
In NetBeans you can hide code in editor folds. Just put the code you would like to hide in between comments of the form:
//<editor-fold defaultstate="collapsed" desc="comment">
//</editor-fold>
For example, I use this to automatically hide code with sensitive information when screen casting, giving presentations, or the like. This way the code is still functional, but I can only expose the parts that are important to the discussion.
//<editor-fold defaultstate="collapsed" desc="API-KEY">
private static final String API_KEY = "Not to be shared";
//</editor-fold>
You can also add a fold by selecting the code you wish to hide with the mouse. A light bulb icon will appear in the editor's margin. Click the light bulb and pick
Surround with //<editor-fold defaultstate="collapsed" desc="comment">...
to have the editor add the needed comments for you.
Upvotes: 6
Reputation: 13728
Netbeans editor allows you to hide (fold):
Discreet statement lines are not part of this list.
Options-->Editor-->General allows you the control of what will be collapsed.
Imagine the mess you would get into, if you have a few selected hidden statement lines and you try to find what goes wrong in a source code you can partially view.
Print statements is not the way you should use in order to test your code. Do it with the excellent Visual Debugger or with JUnit. This way you will have no more issues with mixing debugging print instructions with your actual code.
Upvotes: 2