Hi,
Could you please explain me Swing Threading model. splly invokeLater
method. I am experinced C++ programmer , but new to java.
Should we create another thread in event handler.
pls explain me concepts
hilz - 10 Mar 2006 04:48 GMT
> Hi,
>
> Could you please explain me Swing Threading model. splly invokeLater
> method. I am experinced C++ programmer , but new to java.
> Should we create another thread in event handler.
> pls explain me concepts
http://java.sun.com/products/jfc/tsc/articles/threads/threads3.html
oshinonline@yahoo.com - 10 Mar 2006 05:18 GMT
I hv read that. I have one confusion. If i m creating a SwingWorker
thread from eventhandler. Can this my thread update & access Swing
components.
Senario is in my GUI I have several files opened. When I try to close
these files quickly, it gives me error "AWT-EventQueue-0"
java.lang.ArrayIndexOutOfBoundsException: 11 >=0
at..................................
.......................................
......................................
etc.
In my evenhandler for close button, i create Swing Worker thread to
close that file that needs some server operation & update my GUI.
Could u figure out what's problem
hiwa - 10 Mar 2006 09:50 GMT
Code please. If it is a long and complex production
code, will you post a small demo code that is generally
compilable, runnable and could reproduce your problem.
See: http://homepage1.nifty.com/algafield/sscce.html.
oshinonline@yahoo.com - 10 Mar 2006 12:08 GMT
One more problem:
I ma getting error:
Error in fetching counts from database.
java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Vector.java:432)
at
javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:280)
at javax.swing.JTable.convertColumnIndexToModel(JTable.java:1761)
at javax.swing.JTable.getValueAt(JTable.java:1852)
at
ehpt.bmp.plugins.cdredit.gui.dialogs.CountFilterResultsFrame$1.valueChanged(CountFilterResultsFrame.java:126)
at
javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:187)
at
javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:167)
at
javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:214)
at
javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:408)
at
javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:417)
at
javax.swing.DefaultListSelectionModel.removeSelectionIntervalImpl(DefaultListSelectionModel.java:510)
at
javax.swing.DefaultListSelectionModel.removeSelectionInterval(DefaultListSelectionModel.java:482)
at javax.swing.JTable.checkLeadAnchor(JTable.java:2965)
at javax.swing.JTable.tableChanged(JTable.java:2993)
at javax.swing.JTable.setModel(JTable.java:2827)
at
ehpt.bmp.plugins.cdredit.gui.dialogs.CountFilterResultsFrame.populateTable(CountFilterResultsFrame.java:347)
at
ehpt.bmp.plugins.cdredit.gui.view.CDRRepairMainPanel.populateCountFilterResults(CDRRepairMainPanel.java:425)
at
ehpt.bmp.plugins.cdredit.gui.view.CDRRepairMainPanel.access$1000(CDRRepairMainPanel.java:39)
at
ehpt.bmp.plugins.cdredit.gui.view.CDRRepairMainPanel$9.construct(CDRRepairMainPanel.java:413)
at
ehpt.bmp.plugins.cdredit.gui.dialogs.SwingWorker$2.run(SwingWorker.java:119)
at java.lang.Thread.run(Thread.java:595)
What could be possible cause of error
hiwa - 15 Mar 2006 07:59 GMT
> One more problem:
> I ma getting error:
> Error in fetching counts from database.
> java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
> .....
Let me repeat:
Post a small demo code that is generally compilable, runnable and could
reproduce your problem. See:
http://homepage1.nifty.com/algafield/sscce.html
You have that responsibility to end the thread with an happy-ending.
Don't you think so?
Roedy Green - 10 Mar 2006 05:46 GMT
>Could you please explain me Swing Threading model. splly invokeLater
>method. I am experinced C++ programmer , but new to java.
>Should we create another thread in event handler.
>pls explain me concepts
A normal Java app has many threads, most of which putter away it he
background invisibly. Swing does all its GUI painting on one thread.
This means it has no problems co-ordinating what it dose . It
basically sits in a loop reading events and dispatching them, then
when the event has been handled or a bit of painting done, it pops the
next one off the queue.
to make sure you don interfere with this process you must do most of
your Swing work on the Swing thread, e.g. in your event handlers.
You can create a sort of event and add it to the queue with
SwingUtilities.invoke later. You pass it an object with a run method.
When you packet makes it to the head of the queue it calls your run
method. It does not start up a new thread.
See http://mindprod.com/jgloss/swing.html
http://mindprod.com/jgloss/jgloss/threadsafe.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Paul Hamaker - 15 Mar 2006 09:15 GMT
Oshin, here's an easy explanation of invokeAndWait, invokeLater :
http://javalessons.com/cgi-bin/fun/java-tutorials-main.cgi?ses=ao789&code=ths&sub=gui
--------------------
Paul Hamaker, SEMM, teaching ICT since 1987
http://javalessons.com