Home > Posts > HowTo: Code folding in NetBeans IDE source code editor

HowTo: Code folding in NetBeans IDE source code editor

As explained near the end of https://ui.netbeans.org/docs/ui/code_folding/cf_uispec.html, the NetBeans IDE source code editor supports custom code folding tags for any language, like below (here defining the code folding tag in a Java comment, obviously need to use specific comment syntax for the respective language).

// <editor-fold desc="isUserStudent"> —————————————-

public static boolean isUserStudent(PortletRequest request)
   throws NamingException, PortletServiceUnavailableException,  PumaException, SQLException
{
   return isUserStudent(new DbAccess().getConnection(), request);
}

public static boolean isUserStudent(Connection connection, PortletRequest request)
   throws NamingException, PortletServiceUnavailableException,  PumaException, SQLException
{
   return !StringUtils.isNotPresent(getUserStudentId(connection, request));
}
 
public static boolean isUserStudent(int studentId, PortletRequest request)
   throws NamingException, PortletServiceUnavailableException,  PumaException, SQLException
{
   return isUserStudent(studentId, new DbAccess().getConnection(), request);
}

public static boolean isUserStudent(int studentId, Connection connection, PortletRequest request)
   throws NamingException, PortletServiceUnavailableException,  PumaException, SQLException
{
   return (String.valueOf(studentId).equals(getUserStudentId(connection, request)));
}
 
public static String getUserStudentId(Connection connection, PortletRequest request)
   throws NamingException, PortletServiceUnavailableException,  PumaException, SQLException
{
   return DbStudent.getStudentId(connection, Puma.getUserName(request)); 
}

// </editor-fold>————————————————————-

 

This shows up in NetBeans like below when folded:

image

You can also optionally specify defaultstate="collapsed" at the code folding tag so that when the file is opened that region appears collapsed.

Categories: Posts Tags: , , , , , , ,
  1. No comments yet.
  1. No trackbacks yet.

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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: