我的应用程序运行正常,直到我改变了Nimbus的外观。我收到了以下错误。
它说我的JTable有问题。我已经检查过了,但JTable没有任何问题。
修改
我使用线程并行创建多个JPanel,我认为这导致了错误。删除线程后,它开始正常工作。但由于删除线程,我的应用程序在启动时需要更长的时间。我怎样才能克服这种情况(使用线程和Nimbus外观)?
Exception in thread "Thread-3" java.lang.ClassCastException: javax.swing.plaf.InputMapUIResource cannot be cast to java.awt.Font
at javax.swing.plaf.nimbus.NimbusStyle.getFontForState(NimbusStyle.java:573)
at javax.swing.plaf.synth.SynthStyle.installDefaults(SynthStyle.java:933)
at javax.swing.plaf.nimbus.NimbusStyle.installDefaults(NimbusStyle.java:231)
at javax.swing.plaf.synth.SynthStyle.installDefaults(SynthStyle.java:916)
at javax.swing.plaf.synth.SynthLookAndFeel.updateStyle(SynthLookAndFeel.java:265)
at javax.swing.plaf.synth.SynthButtonUI.updateStyle(SynthButtonUI.java:79)
at javax.swing.plaf.synth.SynthButtonUI.installDefaults(SynthButtonUI.java:62)
at javax.swing.plaf.basic.BasicButtonUI.installUI(BasicButtonUI.java:88)
at javax.swing.JComponent.setUI(JComponent.java:664)
at javax.swing.AbstractButton.setUI(AbstractButton.java:1807)
at javax.swing.JCheckBox.updateUI(JCheckBox.java:228)
at javax.swing.AbstractButton.init(AbstractButton.java:2172)
at javax.swing.JToggleButton.<init>(JToggleButton.java:176)
at javax.swing.JCheckBox.<init>(JCheckBox.java:174)
at javax.swing.JCheckBox.<init>(JCheckBox.java:96)
at javax.swing.plaf.synth.SynthTableUI$SynthBooleanTableCellRenderer.<init>
(SynthTableUI.java:713)
at javax.swing.plaf.synth.SynthTableUI.installDefaults(SynthTableUI.java:116)
at javax.swing.plaf.basic.BasicTableUI.installUI(BasicTableUI.java:1388)
at javax.swing.JComponent.setUI(JComponent.java:664)
at javax.swing.JTable.setUI(JTable.java:3603)
at javax.swing.JTable.updateUI(JTable.java:3645)
at javax.swing.JTable.<init>(JTable.java:637)
at javax.swing.JTable.<init>(JTable.java:562)
at output.Table.initComponents(Table.java:22)
at output.Table.<init>(Table.java:17)
at output.DataTables$3.run(DataTables.java:139)
Exception in thread "Thread-6" java.lang.ClassCastException:
javax.swing.plaf.FontUIResource cannot be cast to java.lang.Number
at javax.swing.AbstractButton.setUIProperty(AbstractButton.java:2240)
at javax.swing.LookAndFeel.installProperty(LookAndFeel.java:280)
at javax.swing.plaf.synth.SynthButtonUI.updateStyle(SynthButtonUI.java:95)
at javax.swing.plaf.synth.SynthButtonUI.installDefaults(SynthButtonUI.java:62)
at javax.swing.plaf.synth.SynthArrowButton$SynthArrowButtonUI.installDefaults
(SynthArrowButton.java:68)
at javax.swing.plaf.basic.BasicButtonUI.installUI(BasicButtonUI.java:88)
at javax.swing.JComponent.setUI(JComponent.java:664)
at javax.swing.AbstractButton.setUI(AbstractButton.java:1807)
at javax.swing.plaf.synth.SynthArrowButton.updateUI(SynthArrowButton.java:51)
at javax.swing.AbstractButton.init(AbstractButton.java:2172)
at javax.swing.JButton.<init>(JButton.java:136)
at javax.swing.JButton.<init>(JButton.java:90)
at javax.swing.plaf.synth.SynthArrowButton.<init>(SynthArrowButton.java:40)
at javax.swing.plaf.synth.SynthScrollBarUI$1.<init>(SynthScrollBarUI.java:378)
at javax.swing.plaf.synth.SynthScrollBarUI.createDecreaseButton
(SynthScrollBarUI.java:378)
at javax.swing.plaf.basic.BasicScrollBarUI.installComponents
(BasicScrollBarUI.java:248)
at javax.swing.plaf.basic.BasicScrollBarUI.installUI(BasicScrollBarUI.java:169)
at javax.swing.JComponent.setUI(JComponent.java:664)
at javax.swing.JScrollBar.setUI(JScrollBar.java:207)
at javax.swing.JScrollBar.updateUI(JScrollBar.java:227)
at javax.swing.JScrollBar.<init>(JScrollBar.java:161)
at javax.swing.JScrollBar.<init>(JScrollBar.java:176)
at javax.swing.JScrollPane$ScrollBar.<init>(JScrollPane.java:718)
at javax.swing.JScrollPane.createHorizontalScrollBar(JScrollPane.java:814)
at javax.swing.JScrollPane.<init>(JScrollPane.java:300)
at javax.swing.JScrollPane.<init>(JScrollPane.java:323)
at output.Table.initComponents(Table.java:27)
at output.Table.<init>(Table.java:17)
at output.DataTables$6.run(DataTables.java:163)
Exception in thread "Thread-5" java.lang.ClassCastException: java.lang.Boolean cannot
be cast to java.awt.Color
at javax.swing.plaf.nimbus.NimbusStyle.getColorForState(NimbusStyle.java:558)
at javax.swing.plaf.synth.SynthStyle.installDefaults(SynthStyle.java:942)
at javax.swing.plaf.nimbus.NimbusStyle.installDefaults(NimbusStyle.java:231)
at javax.swing.plaf.synth.SynthStyle.installDefaults(SynthStyle.java:916)
at javax.swing.plaf.synth.SynthLookAndFeel.updateStyle(SynthLookAndFeel.java:265)
at javax.swing.plaf.synth.SynthScrollBarUI.updateStyle(SynthScrollBarUI.java:80)
at javax.swing.plaf.synth.SynthScrollBarUI.installDefaults
(SynthScrollBarUI.java:67)
at javax.swing.plaf.basic.BasicScrollBarUI.installUI(BasicScrollBarUI.java:168)
at javax.swing.JComponent.setUI(JComponent.java:664)
at javax.swing.JScrollBar.setUI(JScrollBar.java:207)
at javax.swing.JScrollBar.updateUI(JScrollBar.java:227)
at javax.swing.JScrollBar.<init>(JScrollBar.java:161)
at javax.swing.JScrollBar.<init>(JScrollBar.java:176)
at javax.swing.JScrollPane$ScrollBar.<init>(JScrollPane.java:718)
at javax.swing.JScrollPane.createHorizontalScrollBar(JScrollPane.java:814)
at javax.swing.JScrollPane.<init>(JScrollPane.java:300)
at javax.swing.JScrollPane.<init>(JScrollPane.java:323)
at output.Table.initComponents(Table.java:27)
at output.Table.<init>(Table.java:17)
at output.DataTables$5.run(DataTables.java:155)
答案 0 :(得分:0)
(这是一个评论,但被要求作为答案提供)
您是说在多个线程上创建和使用Swing对象时会发生此异常,但在使用单个线程时则不会?这听起来像是一个常见的Swing并发问题,因为Swing不是线程安全的。你必须在EDT上做所有与Swing相关的事情。
关于面板创建过程的主题,也许你可以并行化非Swing对象的创建,然后当你有一个列表或者你拥有的任何东西时,你可以创建面板在EDT上快速实现(我假设非Swing对象的构造需要很长时间才能执行)。