Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I obtain a source file for a Java class and open it in the editor?

class editor file Java obtain source
0
Posted

How do I obtain a source file for a Java class and open it in the editor?

0

Sometimes it is necessary to open source code for a Java file from your NetBeans plug-in. The source code may be located in the currently open projects, in a library or in the platform JRE. It is assumed that libraries and platform JRE have associated sources in your environment. The associations are configured from the Tools > Libraries and Tools > Java Platform menu items. Here is an example of how to find a FileObject corresponding to the class javax.swing.JComponent: String classResource = “javax/swing/JComponent.java”; for (FileObject curRoot : GlobalPathRegistry.getDefault().getSourceRoots()) { FileObject fileObject = curRoot.getFileObject(classResource); if (fileObject != null) { // source file object found // do something, e.g. openEditor(fileObject, lineNumber); return; } } In the if block you can do something with the source file you found. For example, you can open it in the Java editor. DevFaqOpenFileAtLine describes how. How can I open a particular file at a particular lin

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123