java swing中无法添加控件

之前觉得是jdk的问题,重装之后依旧未果,求大神解答。

代码

这就是个很简单入门的demo,可是就是无法运行,运行之后会停止很久然后抛出下面的异常。

 import java.awt.Container;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import org.omg.CORBA.PUBLIC_MEMBER;

public class GameGUI extends JFrame {
    public GameGUI() {
        super("test");
        this.setSize(400,400);
        Container container = this.getContentPane();
        container.setLayout(new FlowLayout());      
        JTextField m = new JTextField(10);
        JLabel o = new JLabel("m:");
        JButton j = new JButton("ok");
        container.add(o);
        container.add(m);
        container.add(j);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        
        this.setVisible(true);      
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        GameGUI gameGUI = new GameGUI();
    }

}

5个回答

重装jdk8和改成jdk7未果,我卸了myeclipse2013换成myeclipse2014就好了。。。具体原因还是不清楚,麻烦诸位了

程序没有问题啊,我这里可以运行出来,很大可能是你的JDK的问题,你是openjdk么?运行图如下:

图片说明

tongyi55555
JonsonJiao 回复Braum: 这个问题是由jdk造成的,你试试换一个看看
接近 5 年之前 回复
FutureFCJ
Braum 不是,就是jdk8
接近 5 年之前 回复

异常

Exception in thread "main" java.lang.Error: Probable fatal error:No fonts found.
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1277)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.initialiseDeferredFonts(FontManager.java:973)
at sun.java2d.SunGraphicsEnvironment.loadFonts(SunGraphicsEnvironment.java:435)
at sun.font.FontManager.findFont2D(FontManager.java:2125)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.initialiseDeferredFonts(FontManager.java:973)
at sun.java2d.SunGraphicsEnvironment.loadFonts(SunGraphicsEnvironment.java:435)
at sun.font.FontManager.findFont2D(FontManager.java:2125)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.initialiseDeferredFonts(FontManager.java:973)
at sun.java2d.SunGraphicsEnvironment.loadFonts(SunGraphicsEnvironment.java:435)
at sun.font.FontManager.findFont2D(FontManager.java:2125)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.initialiseDeferredFonts(FontManager.java:973)
at sun.java2d.SunGraphicsEnvironment.loadFonts(SunGraphicsEnvironment.java:435)
at sun.font.FontManager.findFont2D(FontManager.java:2125)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.initialiseDeferredFonts(FontManager.java:973)
at sun.java2d.SunGraphicsEnvironment.loadFonts(SunGraphicsEnvironment.java:435)
at sun.font.FontManager.findFont2D(FontManager.java:2125)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.initialiseDeferredFonts(FontManager.java:973)
at sun.java2d.SunGraphicsEnvironment.loadFonts(SunGraphicsEnvironment.java:435)
at sun.font.FontManager.findFont2D(FontManager.java:2125)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.initialiseDeferredFonts(FontManager.java:973)
at sun.java2d.SunGraphicsEnvironment.loadFonts(SunGraphicsEnvironment.java:435)
at sun.font.FontManager.findFont2D(FontManager.java:2125)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findOtherDeferredFont(FontManager.java:1086)
at sun.font.FontManager.findDeferredFont(FontManager.java:1103)
at sun.font.FontManager.findFont2D(FontManager.java:2034)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.FontManager.findJREDeferredFont(FontManager.java:1007)
at sun.font.FontManager.findFont2D(FontManager.java:2003)
at sun.font.FontManager.findFont2D(FontManager.java:1985)
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1260)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1148)
at sun.font.CompositeFont.doDeferredInitialisation(CompositeFont.java:236)
at sun.font.CompositeFont.getSlotFont(CompositeFont.java:316)
at sun.font.CompositeStrike.getStrikeForSlot(CompositeStrike.java:59)
at sun.font.CompositeStrike.getFontMetrics(CompositeStrike.java:75)
at sun.font.FontDesignMetrics.initMatrixAndMetrics(FontDesignMetrics.java:345)
at sun.font.FontDesignMetrics.(FontDesignMetrics.java:336)
at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:284)
at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:942)
at javax.swing.JComponent.getFontMetrics(JComponent.java:1607)
at javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(BasicLabelUI.java:210)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1642)
at java.awt.FlowLayout.layoutContainer(FlowLayout.java:594)
at java.awt.Container.layout(Container.java:1419)
at java.awt.Container.doLayout(Container.java:1408)
at java.awt.Container.validateTree(Container.java:1505)
at java.awt.Container.validateTree(Container.java:1511)
at java.awt.Container.validateTree(Container.java:1511)
at java.awt.Container.validateTree(Container.java:1511)
at java.awt.Container.validate(Container.java:1478)
at java.awt.Window.show(Window.java:862)
at java.awt.Component.show(Component.java:1591)
at java.awt.Component.setVisible(Component.java:1543)
at java.awt.Window.setVisible(Window.java:843)
at com.fcj.gui.GameGUI.(GameGUI.java:27)
at com.fcj.gui.GameGUI.main(GameGUI.java:31)
Exception in thread "AWT-EventQueue-0" java.lang.Error: Probable fatal error:No fonts found.
at sun.font.FontManager.getDefaultPhysicalFont(FontManager.java:1277)
at sun.font.FontManager.initialiseDeferredFont(FontManager.java:1156)
at sun.font.CompositeFont.doDeferredInitialisation(CompositeFont.java:236)
at sun.font.CompositeFont.getSlotFont(CompositeFont.java:316)
at sun.font.CompositeStrike.getStrikeForSlot(CompositeStrike.java:59)
at sun.font.CompositeStrike.getFontMetrics(CompositeStrike.java:75)
at sun.font.FontDesignMetrics.initMatrixAndMetrics(FontDesignMetrics.java:345)
at sun.font.FontDesignMetrics.(FontDesignMetrics.java:336)
at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:284)
at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:942)
at javax.swing.JComponent.getFontMetrics(JComponent.java:1607)
at javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(BasicLabelUI.java:210)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1642)
at java.awt.FlowLayout.layoutContainer(FlowLayout.java:594)
at java.awt.Container.layout(Container.java:1419)
at java.awt.Container.doLayout(Container.java:1408)
at java.awt.Container.validateTree(Container.java:1505)
at java.awt.Container.validateTree(Container.java:1511)
at java.awt.Container.validateTree(Container.java:1511)
at java.awt.Container.validateTree(Container.java:1511)
at java.awt.Container.validate(Container.java:1478)
at java.awt.Window.dispatchEventImpl(Window.java:2482)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:674)
at java.awt.EventQueue.access$400(EventQueue.java:81)
at java.awt.EventQueue$2.run(EventQueue.java:633)
at java.awt.EventQueue$2.run(EventQueue.java:631)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:647)
at java.awt.EventQueue$3.run(EventQueue.java:645)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:644)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EveantDispatchThread.jva:122)

这个异常太长了,不过我看了一下,好像说的是没有找到字体,但是我这里没有用需要字体的地方啊

你的插件是什么版本的

FutureFCJ
Braum 你说的是jdk版本吗?1.8.0_51
接近 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐