Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Quickfix won't import JPanel
Quickfix won't import JPanel [message #1858830] Tue, 25 April 2023 13:57 Go to next message
Annette Godtland is currently offline Annette GodtlandFriend
Messages: 2
Registered: April 2023
Junior Member
I just downloaded the latest version of Eclipse for Java Developers, Version 2023-03 (4.27.0)

I created a new Java Project/Package/Class with this code

package annette.godtland.test;

import javax.swing.JFrame;

public class Test extends JFrame {
private JPanel panel = new JPanel();

public static void main(String[] args) {
// TODO Auto-generated method stub

}

}

I get an error that correctly says JPanel cannot be resolved to a type. With my prior version of Eclipse, Version: 2022-06 (4.24.0), QuickFix used to suggest importing javax.swing.JPanel. However, Quickfix in this new version does not make that suggestion. I can type an import statement myself:

import javax.swing.JPanel;

And that makes the error go away. But I would much prefer that Quickfix suggest the fix itself. By the way, the same happens if I try to use a JButton - Quickfix won't suggest it, but I can type the import myself. Is there some setting that turns off the ability of Quickfix to import javax.swing classes?


Re: Quickfix won't import JPanel [message #1858838 is a reply to message #1858830] Wed, 26 April 2023 05:56 Go to previous messageGo to next message
Jay Arthanareeswaran is currently offline Jay ArthanareeswaranFriend
Messages: 128
Registered: July 2009
Senior Member
I am using the same version and I don't see this problem. Quick fix adds the import statement as expected. Do you see anything in the log or anything unusual in the build path?
Re: Quickfix won't import JPanel [message #1858852 is a reply to message #1858838] Wed, 26 April 2023 12:30 Go to previous messageGo to next message
Annette Godtland is currently offline Annette GodtlandFriend
Messages: 2
Registered: April 2023
Junior Member
I just ran through the scenario again this morning. These are the options I selected as I created the class.

I created Test project
Use an execution environment JRE: JavaSE-18
did not select Create module-info.java file

Created annette.godtland.test package
did not select create package-info.java

I created class Test
selected public and non for modifiers
Selected superclass JFrame
selected only one stub: public static void main(String[] args

I added instance variable private JPanel panel = new JPanel();

QuickFix has 3 options, but not to import javax.swing.JPanel

I looked at the build path. It shows that the JRE System Library is in the Modulepath instead of the Classpath

The log shows this warning every time I restart Eclipse:

!ENTRY org.eclipse.egit.ui 2 0 2023-04-26 06:56:21.243
!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git
user global configuration and to define the default location to store repositories: 'C:\Users\jm'. If this is
not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and
EGit might behave differently since they see different configuration options.
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.



I ran the same steps in my Eclipse version 2022-06 where Quickfix works and here are the only differences I see:

Quickfix
2022-06 has 7 options, including import javax.swing.JPanel
2023-03 has 3 options, but not import javax.swing.JPanel

I looked at the build path. It too shows that the JRE System Library is in the Modulepath instead of the Classpath. The Source, Projects, Libraries, Order and Export, and Module dependencies tabs all look identical to what is shown in the 2023-03 version that I am having problems with.

I looked at the installed JREs for each version of Eclipse
2022-06 only has jdk-18.0.2 installed
2023-03 has jdk-18.0.2, jdk-19.0.2, and jdk-10.0.1 installed, but jdk18.0.2 is the default

Both versions of Eclipse log the same warning about the environment variable HOME is not set when I start up Eclipse.
Re: Quickfix won't import JPanel [message #1858853 is a reply to message #1858852] Wed, 26 April 2023 14:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
I wonder if Window -> Preferences -> Java -> Appearance -> Type Filters has java.awt.* check marked for some reason?

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Quickfix won't import JPanel [message #1858884 is a reply to message #1858853] Fri, 28 April 2023 07:46 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Perhaps, but I see this problem pretty regularly on classes that caused no problems for many years. Sometimes just waiting for all the background indexing/compilation to complete allows the import suggestion to appear. Sometimes not. Sometimes ctrl+1 shows the import. Sometimes not. Sometimes saving the file auto-adds the import. Sometimes not - probably because of an ambiguity. Ah! sometimes there is a stale 'bad' import that needs to be manually deleted. Sometimes selecting a different use of the 'import' works; imports in casts are particularly fragile. Sometimes removing a downstream syntax error enables the parse to realize your intent. Some times and understandable but sometimes not. But sometimes there is just no alternative to typing the import manually.

My impression is that this is a progressive decline in performance that has occurred over the last couple of years. Perhaps the complexities of newer Java syntaxes have undermined useful suggestions in badly formed expressions.
Previous Topic:i have a question about the quick picks when you mouse over a error
Next Topic:Enhancement request: Time saver in "run configurations"
Goto Forum:
  


Current Time: Fri Mar 29 14:35:17 GMT 2024

Powered by FUDForum. Page generated in 0.01886 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top