Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pls explain Swing Thread Model

0 views
Skip to first unread message

oshin...@yahoo.com

unread,
Mar 9, 2006, 11:16:34 PM3/9/06
to
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

oshin...@yahoo.com

unread,
Mar 9, 2006, 11:16:38 PM3/9/06
to

hilz

unread,
Mar 9, 2006, 11:48:45 PM3/9/06
to

oshin...@yahoo.com

unread,
Mar 10, 2006, 12:18:42 AM3/10/06
to
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

Roedy Green

unread,
Mar 10, 2006, 12:46:15 AM3/10/06
to
On 9 Mar 2006 20:16:34 -0800, oshin...@yahoo.com wrote, quoted or
indirectly quoted someone who said :

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
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

hiwa

unread,
Mar 10, 2006, 4:50:19 AM3/10/06
to
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.

oshin...@yahoo.com

unread,
Mar 10, 2006, 7:08:12 AM3/10/06
to
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

unread,
Mar 15, 2006, 1:59:38 AM3/15/06
to
> 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 couldYou have that responsibility to end the thread with an happy-ending.
Don't you think so?

Paul Hamaker

unread,
Mar 15, 2006, 3:15:37 AM3/15/06
to
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

0 new messages