Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode won't import java.awt packages

I implemented ActionListener in my java class, but when I tried to auto-import (Shift+Alt+O), it gave this error:

Running the contributed command: '_vscode_delegate_cmd_ksicrwzq' failed.

The whole code is here:

import javax.swing.JFrame;

import javax.swing.JTextField;

public class myframe extends JFrame implements ActionListener{

myframe(){
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(new FlowLayout());
    this.pack();
    this.setVisible(true);

    JTextField text = new JTextField();
    text.setPreferredSize(new Dimension(250,40));
}
like image 680
Baldr Avatar asked Sep 02 '26 20:09

Baldr


2 Answers

I was having similar problem that is VS Code not showing imports for java.awt package as can be seen here. here.

After a lot of research, I came to this link explaining about Working with GUI in VS code.

Solution

Follow the following steps:

Open Command Pallete:

You can open command pallete by pressing Ctrl + Shift + P or ⌘ + Shift + P for mac Users.

Go to Java: Help Center

Command Pallete Search

Go to Students tab:

Navigate to the Student's tab in Java: Help Center

Enable AWT Development

Enabling AWT Development

This procedure solved my issue and now VS Code is providing suggestions for java.awt package.

like image 52
Muhammad Khuzaima Umair Avatar answered Sep 04 '26 11:09

Muhammad Khuzaima Umair


See similar issue report in github: Click the bulbs to Organize imports throws the error.

After Cleaning Java Language Server Workspace from Command Palette, hovering over the code then use Quick Fix to import needed jars instead of keyboard shortcuts. Then the error wouldn't happen again.

like image 23
Molly Wang-MSFT Avatar answered Sep 04 '26 11:09

Molly Wang-MSFT