I wrote a simple project about Swing (without action listener). I want to add a button to a JPanel
and add the panel (named panel
) to a JFrame
(named frame
). But when I added the panel to the frame, Eclipse had an error:
The type javax.swing.JComponent cannot be resolved. It is
indirectly referenced from required .class files
This is my source:
import javax.swing.*;
public class Click {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setTitle("oooooo");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel); //the error
}
}
What should I do?
It seems there is an issue with JRE your eclipse is running on and jre build path is pointing. I suggest you to follow steps:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.