java swing component cannot be resolved

Obviously the problem did not lie in the code, because it worked for everyone else. So I decided do remove and re-install java and eclipse, et voilà! Now it works. Thank you all for your feedback.


I faced the same issue and found that my project was using the Java 8 libraries. I installed the Java 7 library, added the same to the project properties by referencing the library from the installed C:\Program Files\Java folder and the error was gone.

Looks like, the new Java 8 version may a different way to resolve the swing component.


Updating the execution environment under system library to JavaSE-1.7 or JavaSE-1.8 in eclipse should solve the problem. To update the step below can be followed:

> Right-click on the project
> Select properties
> Java build path
> Library > Add Library > Add JRE SYSTEM Library
> Execution Environment
> Select JavaSE-1.7 or JavaSE-1.8
> Finish