Ask coding questions

← Back to all posts
How can I guarantee a restart of the X server from Java Swing?
psb_david_petty (3)

As I posted, shutting down JPanel windows under certain circumstances causes the X server to stay in an intermittent state. I have tried the following:

  • Click the close box w/ window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) configured caused subsequent runs to create windows with partial functionality. (I have since changed to DO_NOTHING_ON_CLOSE.)
  • Right-click on the X server (to enable the fluxbox menu) and exit was a disaster. No graphics worked after that (though I am not sure how to describe it exactly).
  • Closing everything (Chrome, OS, etc.), clearing all browser data, and relogging into This just puts me back into the window unchanged.
  • Waiting overnight seems to have 'reset' the X server (though, how long do users of Java Swing have to wait?).

I would really like to be able to shut down or restart the X server reliably (under control of the .replit file) from a Java Swing repl!

Saibot84 (45)

Try using the shell command pkill x11vnc.

Other commands to try are pkill Xorg or pkill fluxbox.

If all else fails, I believe the whole container can be forcefully restarted with the shell command pkill init