8

Eclipse cant find the import javax.swing.JOptionPane

Where is it located and how can i include it?

import javax.swing.JOptionPane;
5
  • It's included in the JDK. Post your code and the exact error message. Tell us what you have in your build path.
    – JB Nizet
    Commented Jan 6, 2013 at 10:19
  • 3
    import statement is correct. which version of eclipse you using and what type of project you have chose while creating new project?
    – exexzian
    Commented Jan 6, 2013 at 10:21
  • Is your class paths to Java proper.?
    – Jayamohan
    Commented Jan 6, 2013 at 10:52
  • does import javax.swing.*; work? Commented Jan 6, 2013 at 11:34
  • Christian, what version of Eclipse are you using? One of those from eclipse.org? Is your project a java project? Do you have the JDK?
    – Cubic
    Commented Jan 6, 2013 at 11:53

6 Answers 6

14
  1. There must be an installed (and selected) JDK in Eclipse:

    Window > Preferences > Java > Installed JREs   
    
  2. The project must be configured to use that JDK:

    Project > Properties > Java Build Path > Libraries
    

    there should be an entry like "JRE System Library [JDK7]" in the list. If not press:

    Add Library... > JRE System Library
    
  3. The project should have been created as a "Java Project":

    Project > Properties > Builders
    

    should include "Java Builder"

0
9

The accepted answer did not work for me.

This is how I solved it:

Right-Click on your project, select Properties

Go to Java Build Path

Click Libraries, then Add Library ...

Select JRE System Library

Click on Execution environment and select JavaSE-1.7 or JavaSE-1.8

Click Finish, then Apply and Close.

1
  • 1
    This should have been an accepted solution. It worked for me too! Commented Oct 22, 2022 at 8:13
1

Try to Update the execution environment under system library to JavaSE-1.7 or JavaSE-1.8 in eclipse. 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
1

In the beginning when you start to create a new java project just don't click "finish" or "next" directly. But go to the JavaSE version text input at the middle of the form and choose JavaSE 1.6 or 1.7 or 1.8, then click next -> finish. Then it with parse and work.

0

and also what finally added javax library to the project is (as me have also learned from SOF) is: Project name >> right button >> Properties >> Build Path: enter image description here

0

One of my Eclipse projects couldn't find javax.swing The other projects had no problem, the configurations were identical and default.

I found this video on YoutubeVideo of changing the JRE I changed my JRE to 1.7 like suggested in video and it worked. Then, because I thought it was a bug, I changed it back to JRE 17 and it still worked.

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Oct 30, 2023 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.