Edit: If multiple tags are confusing, I am working in Jython.
Here is my SSCCE :
from javax.swing import JFrame window = JFrame('Test', defaultCloseOperation = JFrame.EXIT_ON_CLOSE, size = (800, 600)) window.visible = True
The window opens, sits there for a few seconds, and then closes. So far, the only solution I have found is to add while True: pass to the end, which seems to indicate that the problem is that the window is out of scope, so it clears and closes. In fact, this may be another symptom of the same problem that I encountered earlier .
However, I do not think that wasting cycles in an infinite loop is the best solution. I probably could have done this less problem by sleeping for a few seconds on each cycle, but I still would like to solve it correctly.
Doing the βright pathβ, creating a window on the EDT, gives exactly the same behavior:
from javax.swing import JFrame, SwingUtilities from java.lang import Runnable class Foo(Runnable): def run(self): window = JFrame('Test', defaultCloseOperation = JFrame.EXIT_ON_CLOSE, size = (800, 600)) window.visible = True foo = Foo() SwingUtilities.invokeLater(foo)
In previous applications, this was not a problem, because in any case, I need an infinite loop for other tasks (socket monitoring, etc.). However, my current application is driven entirely by user input, so I don't need / need anything after I invokeLater() .
Update:. Based on the answer to the royal language, I tried to create an instance of one of them:
class JFrameTest(JFrame): def addNotify(self): print 'In addNotify()' JFrame.addNotify(self) def removeNotify(self): print "In removeNotify()" JFrame.removeNotify(self)
"In addNotify ()" is printed, but not "In removeNotify ()", and the window behaves the same. Why won't removeNotify() be called?
Also, I tried doing window.setVisible(True) , not window.visible = True , and this also has no effect.