tags:

views:

551

answers:

7

I'm new to java but I would have thought this was pretty straight foward. I display a JDialog for user input when importing data from a text file but the dialog isn't being painted properly on other computers.

On my computer if I run the program from within NetBeans or from the command prompt then the dialog displays properly. If I run the program on the computer it's supposed to be running on then the inside of the dialog isn't painted - all I see is the border of the dialog then the screen behind it where the controls should be. This computer is running XPSP2 and jre6 update 11.

Does anyone know what could be going wrong?

TIA

A: 

Are you doing all your Swing-related work in the Event Dispatch Thread? If so, are you sure you are not blocking this thread, or doing something slow in it?

Limbic System
+1  A: 

We need to see your code to be sure, but it's most likely you are performing the import on the UI thread, from within some listener code - since you are using the UI thread, no events are processed until you return from the listener.

The solution is to launch a new thread to do the import and then have it trigger events to update the GUI.

Software Monkey
A: 

I'm doing everything in the EDT. There's a lot of code so I won't paste it all but the basic flow is:

(from main)
open csv file for import
read line from file
read product category field
if (category doesn't exist in database)
    display dialog for category code input

...which is where the problem with the dialog is. I didn't think it mattered if non GUI code was executed in the EDT so long as it was all procedural? The only listener I've implemented is for when the ok button is clicked in the dialog but it's not even getting to that point. I am using Hibernate JPA as well (not sure if it's doing anything implicitly).

TIA

But if you are doing this on the EDT, the GUI can't be updated while you are doing the import - per my answer.
Software Monkey
Stupid question: are you sure that "category doesn't exist in database"? If not, then your dialog cannot show...Adding some traces might be useful.
jfpoilpret
A: 

Run the program through a command terminal so you can see if any exceptions are being thrown by your program.

The command will be: java -jar pathtoyourjar.jar

Richie_W
A: 

I do run it from the command prompt and there is no exception.

Thanks

Hey Mark, drop these kinds of remarks in as comments against the answer, rather than as "answers" that are not answers.
Software Monkey
A: 

Even if I change to only displaying the dialog in the EDT and doing everything else in a separate thread, the dialog still doesn't paint properly. Is there something else that could be causing this to happen?

TIA

A: 

The code works in one place but not in another. Computers aren't magic. So there must be some difference between the two computers. The code is Swing GUI code. The three most likely differences are:

  • Different video hardware
  • Different code (probably JRE libraries)
  • Different Swing Look and Feel (probably caused by different OS)

If something about the Java connection to the video hardware is different on the two machines, try and find out what. Do your machine and the target machine both have the latest video drivers etc? Does the target machine have two monitors, or some other difference in video hardware that might cause different code to be executing?

Differences between the two computers eg JRE or OS might cause different code to be executing. You have told us the JRE and OS for the target machine: what about for your machine? Can you find a third machine, or install another JRE so we know if it is the machine or the JRE?

You might have different Swing Look and Feel's on the two machines. Try with a different Look and Feel.

UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());

Just to mention the problem is probably with your code somewhere, and the bug is more likely to be your code than in the Swing Libraries, but this at least might help you work out why everything works on one machine and not on another.

Nick Fortescue