accessing GLCapabilities in subclasses of GLJPanel

Hello,

I have created a class that subclasses GLJPanel, and so far this has worked very well for my purposes. However, I would like to be able to change some of the GLCapabilities (hardwareAcceleration, doubleBuffering, etc…) for the object, and I don’t know how to get access to the GLCapabilities object associated with this particular GLJPanel. I tried creating a GLCapabilities object and passing it to the constructor, but it wouldn’t let me access that member variable until the super constructor had finished finished calling. Also, there is no accessor method that can get me the particular GLCapabilities instance associated with my object, nor is there a way to set it to a new GLCapabilties object I specify after the constructor is called so I’m stumped as to how I could set the GLCapabilities of my object. Here’s some code:


         private GLCapabilities caps = new GLCapabilities();

	public GraphicsComponent() {
		super(caps);
		caps.setHardwareAccelerated(true);
		caps.setDoubleBuffered(true);
	}

the class in question is called GraphicsComponent and it extends GLJPanel (a feature I have used to great success so far, thank you JSR-231!!!)

and the error i get is:


    [javac] Compiling 1 source file to /Users/tojo/Documents/gl_mvt/classes
    [javac] /Users/tojo/Documents/gl_mvt/src/mvt/graphics/GraphicsComponent.java:59: cannot reference caps before supertype constructor has been called
    [javac]             super(caps);
    [javac]                       ^
    [javac] 1 error

any suggestions?

You can write a static method in your subclass which instantiates, sets up and returns a new appropriately-configured GLCapabilities object, and pass the return result of that static method to the superclass’s constructor as argument.