4

I've just started making my first GUI application in Java and I decided to use the NetBeans IDE to do it. I think its working fine so far, except for one problem; it seems to be slow updating the content of a window.

Even in very simple windows with few controls I find that when - for example - closing or resizing a window, I get the normal window border working properly but the inside is completely see through for a second.

It's not the biggest deal in the world, I just find it mildly annoying.

EDIT: I've tried the HelloWorldSwing from the official Java tutorial but I have the same issue, only now, when resizing, instead of being transparent, the new area of the window is black until the contents updates.

ChrisD
  • 3,378
  • 3
  • 35
  • 40
  • I haven't had problems with swing, awt, or any similar framework, so maybe it's you, your machine, your code, etc. Post your code, and we can take a look. – YGL May 19 '10 at 03:35
  • I get the problem with the basic application that is generated by NetBeans when creating a new desktop application project. I could post the code here if you think it would help but doing so would seem a bit redundant. – ChrisD May 19 '10 at 03:47
  • Some code would be useful, as then others could try it too. As mentioned by several other people, I don't have any problems with Swing most of the time. What JVM (and version) and OS are you using? – Mike May 19 '10 at 04:25
  • I'm using Java 6 update 20 on windows vista. As I noted in the edit, I have the same issue with the HelloWorldSwing example from the official Java tutorial: http://java.sun.com/docs/books/tutorial/uiswing/examples/start/HelloWorldSwingProject/src/start/HelloWorldSwing.java – ChrisD May 19 '10 at 05:01
  • In absence of any other information from you, I would wonder whether your hardware is good and powerful enough to run Vista and then Java. Otherwise, it might be good to check that you don't have a background process (eg indexer, antivirus) on your system, eating all available CPU during your tests... – jfpoilpret May 19 '10 at 05:31
  • 1
    You do realize that NetBeans is a Swing application, correct? Does NetBeans seem sluggish to you? If not, then you know that neither your hardware nor Swing are at fault. – Kevin Brock May 19 '10 at 05:44
  • 1
    See http://stackoverflow.com/questions/2779035/changing-the-underlying-background-color-of-a-swing-window – Jonas May 19 '10 at 08:20
  • jfpoilpret, my cpu seems fine when resizing, it gets up to about 50%, which is about the same as when resizing notepad. Kevin, I do realise that and indeed have the same issue with netbeans. Jonas, that is is very helpful and probably answers my question. – ChrisD May 19 '10 at 14:46

3 Answers3

3

You should ensure that all of your GUI updates are performed in the Event Dispatch Thread, and that any other long running tasks are performed in worker threads. If you have long running tasks running in the EDT, your GUI will feel sluggish. Take a look at this tutorial for concepts on Swing Threading.

akf
  • 38,619
  • 8
  • 86
  • 96
  • 2
    Thing is though, it's just a hollow gui at the moment. I built it using the IDE so I haven't even started writing any code yet. – ChrisD May 19 '10 at 03:39
1

In the absence of any technical problems with your app, this could simply be JVM warmup effects. Do updates speed up if you resize the window a few times?

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • I've found that if I keep keep resizing without releasing the mouse button, it eventually works ok. However as soon as I release the mouse button and then start resizing again I get the same problem. – ChrisD May 19 '10 at 03:55
1

This could be a Java2D hardware accelleration issue. Is your 3D graphics card driver fully updated?

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347