0

I know that you should never modify a SWING component on a thread other than the EDT. What if I have a JTable object that I have created using the code:

JTable myTable = new JTable(myTableModel);

but I have not yet added the table to any SWING component. Can I call the JTable methods on a thread in such a case? For example I set up the size, foreground and background colors, column widths, and some other stuff. Can all of this be done on a thread other than the EDT if the table has not been added to the GUI?

user3245747
  • 805
  • 2
  • 17
  • 30
  • 3
    You create the JTable and add it to the Swing GUI on the Event Dispatch thread. No exceptions. You mayupdate your table model in a separate thread, while you're constructing the GUI in the EDT, as long as you pass the table model instance to the JTable when you're creating the GUI. – Gilbert Le Blanc Aug 27 '16 at 12:34
  • To clarify @GilbertLeBlanc's comment: you may `publish()` updates destined for your `TableModel` on a separate thread as long as you `process()` them on the EDT, for [example](http://stackoverflow.com/a/25526869/230513). – trashgod Aug 27 '16 at 14:51
  • Ok thanks. It's clear now. – user3245747 Aug 27 '16 at 15:31

0 Answers0