ClassCastException: javax.swing.plaf.FontUIResource cannot be passed to javax.swing.InputMap

Running the swing application in java, and I got this exception in my program. It is worth noting that this does not appear every time the program starts.

Full stack trace:

Exception in thread "main" java.lang.ExceptionInInitializerError at org.backend.utils.importing.Loading$1.run(Loading.java:54) at org.backend.utils.importing.Loading.loadEverything(Loading.java:61) at org.main.BishopCarrollSchoolTracker.main(BishopCarrollSchoolTracker.java:70) Caused by: java.lang.ClassCastException: javax.swing.plaf.FontUIResource cannot be cast to javax.swing.InputMap at javax.swing.plaf.basic.BasicButtonListener.getInputMap(BasicButtonListener.java:102) at javax.swing.plaf.basic.BasicButtonListener.installKeyboardActions(BasicButtonListener.java:78) at javax.swing.plaf.basic.BasicButtonUI.installKeyboardActions(BasicButtonUI.java:121) at javax.swing.plaf.basic.BasicButtonUI.installUI(BasicButtonUI.java:73) at javax.swing.JComponent.setUI(JComponent.java:662) at javax.swing.AbstractButton.setUI(AbstractButton.java:1782) at javax.swing.plaf.synth.SynthArrowButton.updateUI(SynthArrowButton.java:34) at javax.swing.AbstractButton.init(AbstractButton.java:2149) at javax.swing.JButton.<init>(JButton.java:118) at javax.swing.JButton.<init>(JButton.java:73) at javax.swing.plaf.synth.SynthArrowButton.<init>(SynthArrowButton.java:23) at javax.swing.plaf.synth.SynthScrollBarUI$2.<init>(SynthScrollBarUI.java:325) at javax.swing.plaf.synth.SynthScrollBarUI.createIncreaseButton(SynthScrollBarUI.java:325) at javax.swing.plaf.basic.BasicScrollBarUI.installComponents(BasicScrollBarUI.java:225) at javax.swing.plaf.basic.BasicScrollBarUI.installUI(BasicScrollBarUI.java:147) at javax.swing.JComponent.setUI(JComponent.java:662) at javax.swing.JScrollBar.setUI(JScrollBar.java:190) at javax.swing.JScrollBar.updateUI(JScrollBar.java:210) at javax.swing.JScrollBar.<init>(JScrollBar.java:144) at javax.swing.JScrollBar.<init>(JScrollBar.java:159) at javax.swing.JScrollPane$ScrollBar.<init>(JScrollPane.java:698) at javax.swing.JScrollPane.createHorizontalScrollBar(JScrollPane.java:794) at javax.swing.JScrollPane.<init>(JScrollPane.java:282) at javax.swing.JScrollPane.<init>(JScrollPane.java:305) at org.gui.base.generic.panels.ListTablePanel.<init>(ListTablePanel.java:44) at org.gui.base.main.internal.WorkPanel.<init>(WorkPanel.java:28) at org.gui.base.main.internal.InternalPanel.<clinit>(InternalPanel.java:38) ... 3 more 

The lines that throw the exception (in my source code):

 public static final WorkPanel WORK = new WorkPanel(); 

Go to

 super(new WorkTable(AllWork.getElements(), true, true, true, true, true, true, true), new WorkTable(AllWork.getElements(), true, true, true, true, true, true, true, true)); 

To

 public ListTablePanel(RefreshableTable m, RefreshableTable t) { this.main = m; this.totals = t; setLayout(LayoutFactory.createLayout()); JScrollPane pane = new JScrollPane(main); main.setAutoCreateRowSorter(false); totals.setFont(totals.getFont().deriveFont(Font.BOLD)); totals.setEnabled(false); pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); add(pane, LayoutFactory.newFactory().setFill(GridBagConstraints.BOTH). setY(0).setWeightX(1).setWeightY(1)); add(totals, LayoutFactory.newFactory().setFill(GridBagConstraints.BOTH). setY(1).setWeightX(1).setInsets(new Insets(0, 2, 0, 17))); } 

The final piece of code in my source code is building a JScrollPane .

I do not understand why this exception is thrown.

+4
source share
2 answers

Anytime I see this:

Running the swing application in java, and I got this exception in my program. It is worth noting that this does not appear every time the program starts.

The alarm bells disappear in my head and I think, "Am I handling Swing threads correctly?" Because it is not uncommon for Swing stream errors to cause strange errors that do not always occur.

So, are you passing Swing streams correctly, primarily by initiating and displaying the Swing GUI in the event stream? i.e.,

 private static void createAndShowGui() { // create and display my GUI here } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGui(); } }); } 

By the way, do you not use Nimbus or another look?

+6
source

Bug fixed. Found that I was making GUI stuff at the same time in EDT. The designers took too much time to use invokeLater() , started using invokeAndWait() .

+1
source

Source: https://habr.com/ru/post/1436508/


All Articles