Skip to main content

Strange: AWT-EventQueue-0 and incorrect display in JavaFX table

10 replies [Last post]
asdf_asdf
Offline
Joined: 2008-07-03

His again,

There is this mock application to evaluate binding and display capabilities of javafx that I am trying to debug. I would very appreciate if anyone could provide input in dealing with curios misbehavior i am getting on a rather simple tast )

Basic logic:
JavaFXScript.fx declares StockModel that contains an array of stock objects to be created, updated and displayed on a javafx table GUI element. JavaFXScript also instantiates a StockFeederMock.java object and passes to it StockModel object to populate it with stocks and update them (price attribute) randomly at intervals.

I am getting 2 taunting errors when running the application (the application RUNS though). First is this error message that appears occasionally:
-------------
Updated stock GOG price to 728.4593002979199Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at net.java.javafx.ui.UIContextImpl$XTableCellModel.getValueAt(UIContextImpl.java:2334)
at javax.swing.JTable.getValueAt(JTable.java:2664)
at javax.swing.JTable.prepareRenderer(JTable.java:5681)
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2072)
at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1974)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1770)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
at javax.swing.JComponent.paintComponent(JComponent.java:763)
at javax.swing.JComponent.paint(JComponent.java:1027)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1036)
at javax.swing.JViewport.paint(JViewport.java:747)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1036)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1036)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1036)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5122)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:277)
at javax.swing.RepaintManager.paint(RepaintManager.java:1213)
at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:799)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:284)
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(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 3, Size: 2
-------------

Second is a display error. Instead of displaying stock symbol in the first column of the javafx table and stock price in the second, I see numbers appear in the first column "Symbol" of the table (only in the first row, other rows are displayed correctly) and that some rows disappear and then come back again during runtime. The speed of updates is low enough to exclude possibility that javafx cannot chase them.

Could anyone suggest what could be a reason for such peculiar behavior?

Also please note that I've used array for storing stock information in a javafx model, because the attempts to bind hashmap's changing values to javafx table were unsuccessful.

CODE FOLLOWS:

---JavaFXScript.fx---
[code]
import java.lang.*;
import javafx.ui.*;
import javafx.with.collection.model.*;

System.out.println("Script started...");

public class FxStockModel extends IStockModel {

public attribute stocks:Stock*;

public operation updateStock(symbol:String, price:Number);

public operation createStock(symbol:String, price:Number);

public operation stockExists(symbol:String) : Boolean;
}

operation FxStockModel.updateStock(symbol:String, price:Number) {
var exists:Boolean = false;
for (s in stocks) {
if (s.symbol == symbol) {
//TODO erklaren warum "stocks[indexof s]" statt s.price
//TODO versuchen mit HashMap auf

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
michael_heinrichs
Offline
Joined: 2007-11-15

@walterln:
Yes, you are right.

Message was edited by: michael_heinrichs

asdf_asdf
Offline
Joined: 2008-07-03

@ michael_heinrichs

you possess wealth of knowledge ))) did you study APIs/developed them? Is there a resorce (a book maybe) that you could recommend to get to the intricacies and latest syntax of JavaFX? I am having troubles finding anything comprehensive.

thanks

michael_heinrichs
Offline
Joined: 2007-11-15

Thanks and yes, I am part of the compiler-team.

Documentation is currently a problem. JavaFX is still in a very early stage, Any documentation you write today is probably out-of-date in one or two weeks.

There is the official documentation (Language Reference and API). It is probably the most up-to-date documentation you can get currently.
http://openjfx.java.sun.com/current-build/doc/index.html

There are some articles on SDN and Planet JFX Wiki, although some are probably already outdated.
http://java.sun.com/javafx/reference/
http://jfx.wikia.com/wiki/Main_Page

You can find a number of blogs, probably the best one is from James Weaver.
http://learnjavafx.typepad.com/

Well, and last but not least there is the source-code... :-)

michael_heinrichs
Offline
Joined: 2007-11-15

The first issue I noticed is you are using a Java-Timer together with JavaFX. That is pretty evil and should be avoided. It is very likely you are running into some synchronizations issues (might even be the root cause of the problem here.) I suggest to write the StockFeederMock in JavaFX using a Timeline.

Switch to compiled JavaFX and to the new UI-library (packages javafx.gui.*). I don't know how to use JavaFX with eclipse, there should be a plugin, but I don't know its current state. I know for sure, that the plugins for NetBeans and IntelliJ are up to date. Also there is always the option to use the compiler from the command-line.

Is there a reason why you are using the ScriptEngine? Maybe you can start with a "standard" JavaFX-application first and rewrite it to use the ScriptEngine later.

Is it possible to format the code you are posting? It is really hard to read it without proper formatting.

walterln
Offline
Joined: 2007-04-17

I assume a javax.swing.Timer or updating the model in a EventQueue.invokeLater() would work as well? That is, JavaFX does use Swing with its [url=http://java.sun.com/docs/books/tutorial/uiswing/concurrency/dispatch.html]EDT[/url] under the hood?

asdf_asdf
Offline
Joined: 2008-07-03

His!
@shahbazc i used "javafxc -d ." and "javafx" commands from the command line instead to compile my script and launch it subsequently. Everything works without throwing exceptions this time. thanks.

@michael_heinrichs and @walterln, i ran that from command line and see no errors anymore. (I see implementing a timeline from within of JavaFX as not practical, since Timer would most likely stay in the objects to which I want to bind my JavaFX later) Could it be that my code is not affected by the synchronization issues anymore, since now JavaFX class starts everything instead of being started by a java class?

Code formatted now )

The reason I used ScriptEngine is because I simply saw it used in several online tutorials. I am having troubles finding a good set of tutorials that relate to the latest compiled version of JavaFX and new syntax, would you suggest a resource?

I am posting the new version of the code for information purposes. Also, what I noted, is that if the list of stocks becomes excessive (have seen when it's >1100), then only a part of the stocks is displayed on the table (without errors being thrown in the command line).

michael_heinrichs
Offline
Joined: 2007-11-15

No, how you start the application should not have an effect on synchronization issues. If you want to write the timer in Java, follow one of walterln's suggestions to avoid synchronization issues.

If the error happens in a bind, exceptions are swallowed by default. There is a switch to enable the exceptions. I think, you have to use "javafx -Djavafx.debug=true".

shahbazc
Offline
Joined: 2008-04-06

I'm getting the exact same error (although I'm using the compiled version of JavaFX, where as you seem to be using the interpreted version).

My JMS feed is populating a JavaFX table. My data object is only eight fields wide so it is the out of bounds exception seems to be connected to the number of rows.

My application also comes up and actually displays data (if I didn't notice the exceptions, I would think the app was running fnie)

------------------------------

Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 22, Size: 11
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at com.sun.javafx.api.ui.UIContextImpl$XTableCellModel.getValueAt(UIContextImpl.java:903)
at javax.swing.JTable.getValueAt(JTable.java:2638)
at javax.swing.JTable.prepareRenderer(JTable.java:5652)
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2072)
at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1974)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1770)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
at javax.swing.JComponent.paintComponent(JComponent.java:763)
at javax.swing.JComponent.paint(JComponent.java:1027)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1036)
at javax.swing.JViewport.paint(JViewport.java:747)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1036)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1036)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1036)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5122)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:285)
at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:723)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
...
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 58, Size: 16
...
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 58, Size: 0
...
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 50, Size: 0
...
etc.

asdf_asdf
Offline
Joined: 2008-07-03

Hi shahbazc,

How could i switch from an interpreted to a compiled version of the JavaFX? I am currently developing under Eclipse with classpath in my project pointing at the latest libraries from the subversion.

I am not getting how that exception could be related to the number of rows, since there are only 4 stocks being updated?

cheers!

shahbazc
Offline
Joined: 2008-04-06

Hi,
Since netbeans seems to be much more up to date with JavaFX developments, I am using that. Just follow the directions here: http://javafx.netbeans.org/download-compiler-JFXplugin.html

(make sure you are using netbeans version 6.1, not 6.5)