1

I'm developing an application, in which all UI components are defined via an XML file. I read the xml and depeding on it the UI is composed. After the user made some changes a new XML is provided and the UI is refreshed accordingly. Now I get some really annoying rendering issues, especially with several scroll areas, where either parts of the UI are cut of (and only get visible, when I resize the window) or the scrollbar is alread scrolled to some point, but it should just show the top of the content.

I assume this is an Event Dispatch Thread issue and found some really useful info about it here: http://www.javapractices.com/topic/TopicAction.do?Id=153

You can read there:"This thread (the EDT) becomes active after a component becomes realized : either pack, show, or setVisible(true) has been called"

Parsing the XML is not done in the EDT and also instantiating the components and adding them to their parent panels. Only after all components are created they are finally added to the MainPane via the EDT. However is seems in some cases creating components and adding them to panels, already starts the EDT. So things get messed up.

Does someone have detailed knowledge which methods call pack, show, or setVisible(true) and therefore start the EDT?

Thanks a lot

mKorbel
  • 109,525
  • 20
  • 134
  • 319
haferblues
  • 2,155
  • 4
  • 26
  • 39
  • 2
    _Does someone have detailed knowledge which methods call pack, show, or setVisible(true)_ Well you are calling one of those methods and therefore trigger the intitialisation of the EDT. Anyway, just to simplify your life, create all your UI-stuffs on the EDT. You can easily perform that with `SwingUtilities.invokeLater()` and `SwingUtilities.invokeAndWait()` – Guillaume Polet Jan 07 '13 at 09:05
  • 1
    @haferblues : But do remember to watch for `SwingUtilities.invokeAndWait()`, this one is a bit trickier to use than the former one. It might can lead to `deadlocks/run conditions` and stuff if not dealt with carefully. – nIcE cOw Jan 07 '13 at 09:17
  • 3
    first stop in basic issues is reading the [corresponding chapter](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/) of _the_ tutorial on it :-) In short: "realized" is no longer a valid notion, each and every access to the any property of all Swing components **must** happen on the EDT, always. – kleopatra Jan 07 '13 at 10:47

1 Answers1

2

I had the same issues with scroll panes, try setting the following property on them:

scrollpane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);

As in the comments, all Swing components must be created on the EDT or your going to get weird stuff happening.

Andy Till
  • 3,371
  • 2
  • 18
  • 23
  • @haferblues smells strongly like doctoring on symptoms ... be sure to track and solve the _real_ problem, it'll bite you again sooner or later ;-) – kleopatra Jan 09 '13 at 12:45
  • Quite probably, but sometimes you just want to move on and work on what you were supposed to. Especially if it is for fun as it was when I had the problem. – Andy Till Jan 09 '13 at 12:49