一段简单程序, frame.add(lbl);出现 问题。 也不知道为什么就是这里, 而我Ctrl + Shift + T 确实也是没有发现 JComponent 。

public void displayImage(String title, Image img, int x, int y)
{
    ImageIcon icon=new ImageIcon(img);
    JFrame frame=new JFrame(title);
    JLabel lbl=new JLabel(icon);
    frame.add(lbl);//  ERROR
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocation(x, y);
    frame.setVisible(true);
}

奇了怪了!我猜是jdk版本的问题,但是为什么呢? 难道不能用jdk8 ? 可是项目的其他代码都是依赖jdk8 的?

网上查看半天没有找到解决方案! stackoverflow 也没有! 郁闷! 后面偶然发现这个 :

http://blogs.candoerz.com/question/155925/java-swing-component-cannot-be-resolved.aspx

我大概明白了,应该还是jdk8 在myeclipse10 的不兼容的问题。 具体来说是我的 myeclipse10 的java compliation level 只能是 7, 所以。。。

The type javax.swing.JComponent cannot be resolved. It is indirectly referenced from required .class files

换成 ideaj, 问题解决! 又是 jdk8 在myeclipse 的不兼容的问题啊!

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-11
  • 2021-10-07
  • 2019-09-28
  • 2021-07-10
  • 2021-11-29
  • 2021-09-28
相关资源
相似解决方案