Adding New Tabs to the Project Properties Dialog in NetBeans IDE
Let's extend the Project Properties dialog of an existing project type in NetBeans IDE (or any application on the NetBeans Platform that makes use of the NetBeans IDE's project system):
To achieve the above, we'll create a small NetBeans module with this structure:
Now, for the code. We'll be using the @ProjectCustomizer.CompositeCategoryProvider.Registration annotation for generating layer.xml entries at compile time, which is a new annotation in NetBeans Platform 6.8, therefore the following applies to NetBeans Platform 6.8 only:
import java.util.ResourceBundle;
import javax.swing.JComponent;
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
public class AdditionalJ2SECompositePanelProvider implements ProjectCustomizer.CompositeCategoryProvider {
private static final String MURPHY1 = "Murphy1";
private static final String MURPHY2 = "Murphy2";
@ProjectCustomizer.CompositeCategoryProvider.Registration(projectType = "org-netbeans-modules-java-j2seproject", position = 100)
public static AdditionalJ2SECompositePanelProvider createMurphy1() {
return new AdditionalJ2SECompositePanelProvider(MURPHY1);
}
@ProjectCustomizer.CompositeCategoryProvider.Registration(projectType = "org-netbeans-modules-java-j2seproject", position = 200)
public static AdditionalJ2SECompositePanelProvider createMurphy2() {
return new AdditionalJ2SECompositePanelProvider(MURPHY2);
}
private String name;
private AdditionalJ2SECompositePanelProvider(String name) {
this.name = name;
}
@Override
public Category createCategory(Lookup lkp) {
ResourceBundle bundle = NbBundle.getBundle(AdditionalJ2SECompositePanelProvider.class);
ProjectCustomizer.Category toReturn = null;
if (MURPHY1.equals(name)) {
toReturn = ProjectCustomizer.Category.create(
MURPHY1,
bundle.getString("LBL_Config_Murphy1"),
null);
} else {
toReturn = ProjectCustomizer.Category.create(
MURPHY2,
bundle.getString("LBL_Config_Murphy2"), // NOI18N
null);
}
return toReturn;
}
@Override
public JComponent createComponent(Category category, Lookup lkp) {
String nm = category.getName();
if (MURPHY1.equals(nm)) {
return new NewJPanel1();
} else {
return new NewJPanel2();
}
}
}
Reference is made above to the Bundle file, containing these keys:
LBL_Config_Murphy1=Murphy 1
LBL_Config_Murphy2=Murphy 2
Read the related Javadoc, i.e., the ProjectCustomizer class.
Believe it or not, with very little coding (and no painful layer.xml registrations)... you're done! Run the application and look in the Project Properties dialog of a Java project in NetBeans IDE, since that's the project type for which the above has been registered. There you should see your new tabs.





Comments
Adam Metzler replied on Mon, 2010/02/15 - 2:27pm
Mark Petrovic replied on Tue, 2010/08/03 - 9:37am
Mark Petrovic replied on Tue, 2010/08/03 - 10:13am
Javier Ortiz replied on Fri, 2012/07/20 - 11:23am
Matt Coleman replied on Thu, 2012/08/23 - 12:42am
wow..u can now add more tabs..way cool technique
graphic artist buffalo
Mateo Gomez replied on Thu, 2012/08/23 - 12:50am
in response to:
Mark Petrovic
yes,,.i hope this can work out coz it be much convenient to add in the jpanel
mexican dessert recipes
Mateo Gomez replied on Thu, 2012/08/23 - 12:52am
hi Sean,
this is such a wonderful project..i will be checking out your blog.
mexican dessert recipes
Xavier Figueroa replied on Wed, 2013/02/06 - 7:33pm
Excellent post !
Can you tell me What is the content of NewJPanel1.java and NewJPanel2.java?