package com.yourpackage; import java.awt.*; import java.awt.event.InputEvent; import javax.swing.*; import com.jogamp.opengl.*; import com.jogamp.opengl.awt.GLCanvas; public class cTestGLContextException static final Point CANCEL_POSITION = new Point(697, 471); static public void AutoCancelChooser(int delay) { new Thread() { public void run() { try { Robot robot = new Robot(); // wait robot.delay(delay); // move Point origin = MouseInfo.getPointerInfo().getLocation(); Point destination = CANCEL_POSITION; int nbIterations = 100; for (int i = 1; i <= nbIterations; i++) { float alpha = i / (float) nbIterations; robot.mouseMove((int) (origin.x * (1 - alpha) + destination.x * alpha), (int) (origin.y * (1 - alpha) + destination.y * alpha)); robot.delay(5); } // click robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); } catch (AWTException e) { e.printStackTrace(); } } }.start(); } static public void Test() { final int NB_TEST = 5; final int DELAY = 2500; final GLCapabilities CAPS = new GLCapabilities(GLProfile.getDefault()); for (int i = 0; i < NB_TEST; i++) { System.out.println(" -> iteration " + i + " on " + NB_TEST); try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { // base dialog JDialog dialog = new JDialog((Window) null); dialog.setMinimumSize(new Dimension(500, 300)); dialog.setPreferredSize(new Dimension(500, 300)); dialog.setModal(false); dialog.setVisible(true); // build accessory JPanel panel = new JPanel(new BorderLayout()); GLCanvas canvas = new GLCanvas(CAPS); canvas.display(); panel.add(canvas); panel.setPreferredSize(new Dimension(300, 300)); // create file chooser with accessory JFileChooser fileChooser = new JFileChooser(); fileChooser.setAccessory(panel); // launch robot closer AutoCancelChooser(DELAY); fileChooser.showOpenDialog(dialog); // dispose of resources dialog.setVisible(false); dialog.dispose(); canvas.destroy(); } }); } catch (Throwable e) { e.printStackTrace(); } } } static public void main(String[] pArgs) { Test(); } }