Custom indicators, trading strategies, data export and recording and more...
-
zcsoka
- Posts: 292
- Joined: Thu Dec 19, 2019 7:50 pm
- Has thanked: 2 times
- Been thanked: 28 times
Post
by zcsoka » Mon Mar 08, 2021 12:55 pm
Greetings,
I am developing an indicator, which will display indicators in the bottom panel and will also show a widget in a popup JFrame window with continuous updates. The popup uses a JFrame, an extended JPanel and a JProgressbar. When the package is added to the running instance of Bookmap, everything works fine, the widget is displayed and updated. When the Bookmap is shut down and started again, at startup time it throws and EDT violation exception on creating the extended JPanel (DrawPanel). As far as I am concerned, the action is executed on the correct thread, I cannot figure out what is causing the exception. Could you please give me some lead how to investigate the problem? It seems it is triggered on the BookmapFailOnThreadViolationRepaintManager.
Many thanks in advance,
Kind Regards,
Zoltan
Code: Select all
20210308 12:39:36.321(UTC) WARN: Potentially unsafe UI access detected (EDT violation)
org.assertj.swing.exception.EdtViolationException: EDT violation detected
at java.base/java.lang.Thread.getStackTrace(Unknown Source)
at org.assertj.swing.edt.CheckThreadViolationRepaintManager.checkThreadViolations(CheckThreadViolationRepaintManager.java:82)
at org.assertj.swing.edt.CheckThreadViolationRepaintManager.addDirtyRegion(CheckThreadViolationRepaintManager.java:65)
at org.assertj.swing.edt.BookmapFailOnThreadViolationRepaintManager.addDirtyRegion(SourceFile:44)
at java.desktop/javax.swing.JComponent.repaint(Unknown Source)
at java.desktop/java.awt.Component.repaint(Unknown Source)
at java.desktop/javax.swing.JComponent.setFont(Unknown Source)
at java.desktop/javax.swing.LookAndFeel.installColorsAndFont(Unknown Source)
at java.desktop/javax.swing.plaf.basic.BasicPanelUI.installDefaults(Unknown Source)
at java.desktop/javax.swing.plaf.basic.BasicPanelUI.installUI(Unknown Source)
at java.desktop/javax.swing.JComponent.setUI(Unknown Source)
at java.desktop/javax.swing.JPanel.setUI(Unknown Source)
at java.desktop/javax.swing.JPanel.updateUI(Unknown Source)
at java.desktop/javax.swing.JPanel.<init>(Unknown Source)
at java.desktop/javax.swing.JPanel.<init>(Unknown Source)
at java.desktop/javax.swing.JPanel.<init>(Unknown Source)
at com.bookmap.api.paceoftape.indicators.DrawPanel.<init>(paceoftape.java:369)
at com.bookmap.api.paceoftape.indicators.paceoftape.initialize(paceoftape.java:129)
at velox.api.layer1.simplified.InstanceWrapper.start(InstanceWrapper.java:122)
at velox.api.layer1.simplified.SimplifiedL1ApiLoader.startForInstrument(SimplifiedL1ApiLoader.java:352)
at velox.api.layer1.simplified.SimplifiedL1ApiLoader.addInstrument(SimplifiedL1ApiLoader.java:513)
at velox.api.layer1.simplified.SimplifiedL1ApiLoader.onInstrumentAdded(SimplifiedL1ApiLoader.java:497)
-
zcsoka
- Posts: 292
- Joined: Thu Dec 19, 2019 7:50 pm
- Has thanked: 2 times
- Been thanked: 28 times
Post
by zcsoka » Wed Mar 10, 2021 8:46 am
Hi Svyatoslav,
I was under the impression, that the Add-ins were running in an EDT thread, by bad. I encapsulated the Swing UI tasks in a separate thread with SwingUtilities, it is running fine. Thanks for the clarification.
-
rickbarlow
- Posts: 43
- Joined: Mon Feb 08, 2021 5:37 pm
- Been thanked: 1 time
Post
by rickbarlow » Thu Jun 03, 2021 7:15 pm
I received this same issue when I tried to add Swing functionality to pop-up a window to serve as a logger, and fill-in a frame with logging information. I can get the error to go away when I wrap the 2 methods is use (1. create the window with frame, and 2. add a JLabel to the panel). But when I do so, I never see the JLabels added to the UI. Is there something else I need to do to get it to work properly? See below, thank you!
public void createWindow() {
if (SwingUtilities.isEventDispatchThread()) {
createWindowInner();
} else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createWindowInner();
}
});
}
}
public void createWindowInner() {
frame = new JFrame("MBO");
jp = new JPanel();
jp.setLayout(new BoxLayout(jp, BoxLayout.PAGE_AXIS));
scroll = new JScrollPane(jp);
frame.setContentPane(scroll);
frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);
frame.setSize(450, 850);
}
public void setContent(String s) {
if (SwingUtilities.isEventDispatchThread()) {
setContentInner(s);
} else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
setContentInner(s);
}
});
}
}
public void setContentInner(String s) {
JLabel l = new JLabel();
l.setText(s);
l.setEnabled(true);
jp.add(l);
JScrollBar sb = scroll.getVerticalScrollBar();
sb.setValue(sb.getMaximum());
}
-
rickbarlow
- Posts: 43
- Joined: Mon Feb 08, 2021 5:37 pm
- Been thanked: 1 time
Post
by rickbarlow » Fri Jun 04, 2021 12:39 pm
The only difference I see is that when I add the invokeLater wrappers, I get no runtime errors, but, the Jlabels do not become visible in the panel/window -- versus -- if I don't wrap them, occasionally throughout the running time, I get an error message indicating either an EDT violation, or a painter error. See 2 example errors below
--
Full report content:
velox.bookmap.qc: org.assertj.swing.exception.EdtViolationException: EDT violation detected
at velox.bookmap.qc.a(SourceFile:58)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: org.assertj.swing.exception.EdtViolationException: EDT violation detected
at java.base/java.lang.Thread.getStackTrace(Thread.java:1598)
at org.assertj.swing.edt.CheckThreadViolationRepaintManager.checkThreadViolations(CheckThreadViolationRepaintManager.java:82)
at org.assertj.swing.edt.CheckThreadViolationRepaintManager.addDirtyRegion(CheckThreadViolationRepaintManager.java:65)
at org.assertj.swing.edt.BookmapFailOnThreadViolationRepaintManager.addDirtyRegion(SourceFile:44)
at java.desktop/javax.swing.JComponent.repaint(JComponent.java:4836)
at java.desktop/java.awt.Component.repaint(Component.java:3394)
at java.desktop/javax.swing.JComponent.setBorder(JComponent.java:1815)
at java.desktop/javax.swing.plaf.synth.SynthStyle.installDefaults(SynthStyle.java:915)
at java.desktop/javax.swing.plaf.synth.SynthLookAndFeel.updateStyle(SynthLookAndFeel.java:270)
at java.desktop/javax.swing.plaf.synth.SynthLabelUI.updateStyle(SynthLabelUI.java:69)
at java.desktop/javax.swing.plaf.synth.SynthLabelUI.installDefaults(SynthLabelUI.java:64)
at java.desktop/javax.swing.plaf.basic.BasicLabelUI.installUI(BasicLabelUI.java:343)
at java.desktop/javax.swing.JComponent.setUI(JComponent.java:685)
at java.desktop/javax.swing.JLabel.setUI(JLabel.java:256)
at java.desktop/javax.swing.JLabel.updateUI(JLabel.java:270)
at java.desktop/javax.swing.JLabel.<init>(JLabel.java:162)
at java.desktop/javax.swing.JLabel.<init>(JLabel.java:233)
at velox.api.layer1.simplified.demo.RB_MBOWindow.setContentInner(RB_MBOWindow.java:93)
at velox.api.layer1.simplified.demo.RB_MBOWindow.setContent(RB_MBOWindow.java:74)
at velox.api.layer1.simplified.demo.RB_CVDImbalancev4.send(RB_CVDImbalancev4.java:989)
at velox.api.layer1.simplified.InstanceWrapper.send(InstanceWrapper.java:394)
at velox.api.layer1.simplified.DeactivatableStrategyUpdateGeneratorWithFilter.onMboSend(DeactivatableStrategyUpdateGeneratorWithFilter.java:115)
at jdk.internal.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
----
Full report content:
java.lang.ClassCastException: class java.awt.Color cannot be cast to class javax.swing.Painter (java.awt.Color and javax.swing.Painter are in module java.desktop of loader 'bootstrap')
at java.desktop/javax.swing.plaf.nimbus.NimbusStyle.getBackgroundPainter(NimbusStyle.java:722)
at java.desktop/javax.swing.plaf.nimbus.SynthPainterImpl.paintBackground(SynthPainterImpl.java:100)
at java.desktop/javax.swing.plaf.nimbus.SynthPainterImpl.paintLabelBackground(SynthPainterImpl.java:754)
at java.desktop/javax.swing.plaf.synth.SynthLabelUI.update(SynthLabelUI.java:171)
at java.desktop/javax.swing.JComponent.paintComponent(JComponent.java:797)
at java.desktop/javax.swing.JComponent.paint(JComponent.java:1074)
at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:907)
at java.desktop/javax.swing.JComponent.paint(JComponent.java:1083)
at java.desktop/javax.swing.JComponent.paintToOffscreen(JComponent.java:5255)
at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBufferedImpl(RepaintManager.java:1643)
at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1618)
at java.desktop/javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1556)
at java.desktop/javax.swing.RepaintManager.paint(RepaintManager.java:1323)
at java.desktop/javax.swing.JComponent._paintImmediately(JComponent.java:5203)
at java.desktop/javax.swing.JComponent.paintImmediately(JComponent.java:5013)
at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:865)
at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:848)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:848)
at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:823)
at java.desktop/javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:772)
at java.desktop/javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1884)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at velox.ib.O.dispatchEvent(SourceFile:70)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
at velox.api.layer1.exceptionwrapper.a$b.invoke(SourceFile:64)
at com.sun.proxy.$Proxy80.onMboSend(Unknown Source)
at velox.bookmap.bw.onMboSend(SourceFile:46)
at velox.api.layer1.layers.aZ.a(SourceFile:942)
at velox.api.layer1.layers.aZ.a(SourceFile:896)
at velox.api.layer1.layers.aZ.b(SourceFile:753)
... 1 more
-
Andry API support
- Posts: 548
- Joined: Mon Jul 09, 2018 11:18 am
- Has thanked: 25 times
- Been thanked: 85 times
Post
by Andry API support » Fri Jun 04, 2021 2:16 pm
I never see the JLabels added to the UI
Try to call revalidate() and repaint() for a Container you are adding the lables to if it is visible already.