Well, for one thing, JOptionPane is a Swing class, and you may only use Swing classes and methods on the Swing/AWT event dispatch thread (EDT). So, you're breaking the Swing threading rules and are potentially going to see some strange behavior because of that. However, I doubt that's what's causing the problem you describe.
Anyway:
Above you can see the entire code of 'LevelPicker'.
That's clearly not the entire code of LevelPicker, since I don't see any import statements nor the definitions for methods level3, level4 etc.
I think that essentially the problem is not what you think it is. You've got this idea that Greenfoot.setWorld(...) is not working in certain cases, but that's almost certainly not correct. But because you've got this idea, you're only posting snippets of code around your calls to Greenfoot.setWorld(...). You need to post more of the code, I think. Try to get it it down to a small example which still doesn't behave as you expect, and post the entire code for that.

