runelite-client/src/main/java/net/runelite/client/util/SwingUtil.java
/**
	 * Add graceful exit callback.
	 *
	 * @param frame           the frame
	 * @param callback        the callback
	 * @param confirmRequired the confirm required
	 */
Add graceful exit callback.
@param frame           the frame
@param callback        the callback
@param confirmRequired the confirm required
Add graceful exit callback . @param frame the frame @param callback the callback @param confirmRequired the confirm required
public static void addGracefulExitCallback(@Nonnull final JFrame frame, @Nonnull final Runnable callback, @Nonnull final Callable<Boolean> confirmRequired)
	{
		frame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		frame.addWindowListener(new WindowAdapter()
		{
			@Override
			public void windowClosing(WindowEvent event)
			{
				int result = JOptionPane.OK_OPTION;
				try
				{
					if (confirmRequired.call())
					{
						result = JOptionPane.showConfirmDialog(
							frame,
							"Are you sure you want to exit?", "Exit",
							JOptionPane .OK_CANCEL_OPTION,
							JOptionPane.QUESTION_MESSAGE);
					}
				}
				catch (Exception e)
				{
					log.warn("Unexpected exception occurred while check for confirm required", e);
				}
				if (result == JOptionPane.OK_OPTION)
				{
					callback.run();
					System.exit(0);
				}
			}
		});
	}
public static void addGracefulExitCallback ( @ Nonnull final JFrame frame , @ Nonnull final Runnable callback , @ Nonnull final Callable < Boolean > confirmRequired ) { frame . setDefaultCloseOperation ( DO_NOTHING_ON_CLOSE ) ; frame . addWindowListener ( new WindowAdapter ( ) { @ Override public void windowClosing ( WindowEvent event ) { int result = JOptionPane . OK_OPTION ; try { if ( confirmRequired . call ( ) ) { result = JOptionPane . showConfirmDialog ( frame , "Are you sure you want to exit?" , "Exit" , JOptionPane . OK_CANCEL_OPTION , JOptionPane . QUESTION_MESSAGE ) ; } } catch ( Exception e ) { log . warn ( "Unexpected exception occurred while check for confirm required" , e ) ; } if ( result == JOptionPane . OK_OPTION ) { callback . run ( ) ; System . exit ( 0 ) ; } } } ) ; }
Add graceful exit callback.
Add graceful exit callback .