Results 1 to 2 of 2
  1. #1
    timmycafe is offline Member
    Join Date
    Nov 2014
    Rep Power

    Question How to attach opengl display to a JFrame and dispose of it properly?

    I am new to this website and i am needing some help. How can i attach the OpenGl display to a JFrame and so that when i close the JFrame is destroys the display? Here is my code so far:

    Java Code:
    package test.core;
    import java.awt.BorderLayout;
    import java.awt.Canvas;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowListener;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    import org.lwjgl.LWJGLException;
    import org.lwjgl.opengl.Display;
    import org.lwjgl.opengl.DisplayMode;
    import org.lwjgl.opengl.GL11;
    import static org.lwjgl.opengl.GL11.*;
    public class Main {
        private static CreateCanvas canvas;
        private static CreateFrame frame;
        private static int width = 800;
        private static int height = 600;
        public static void main(String[] args) throws InterruptedException {
        public static void cleanUp() {
        private static void startDisplay() {
            }catch(LWJGLException ex)
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        private static void startFrames()
            Runnable r = new Runnable(){
                public void run(){
                    frame = new CreateFrame();
                    JButton button = new JButton("BUTTON");
                    canvas = new CreateCanvas();
                    JPanel panel = frame.panel;
                    canvas.setSize(300, 300);
                    frame.setSize(width, height);
                    WindowListener listen = new WindowAdapter(){
                        public void windowClosing(WindowEvent we){
                            int result = JOptionPane.showConfirmDialog(frame, "Do you want to quit the Application?");
                            if(result == JOptionPane.OK_OPTION){
    I had the opengl display attach to the JFrame before i did the runnable. But after adding the runnable the display now shows up the same size as my screen size. I have tried rearranging the
    Java Code:
    and the

    Java Code:
    but nothing changes the opengl display is still the same size and when i try to close the JFrame first rather then close the display first i get this error:

    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: From thread Thread[AWT-EventQueue-0,6,main]: Thread[main,5,main] already has the context current
    which points me to my

    Java Code:
    which im guessing is telling me that i am not properly disposing the display? Can anyone help me attach the opengl display to the JFrame and fix the error above?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: How to attach opengl display to a JFrame and dispose of it properly?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. JFrame dispose() works only first time
    By StainedWolf in forum AWT / Swing
    Replies: 10
    Last Post: 08-16-2014, 01:02 AM
  2. JFrame not responding to dispose() function
    By amitSingh in forum New To Java
    Replies: 15
    Last Post: 06-14-2014, 08:17 AM
  3. Dispose Jframe from another class.
    By vahshir in forum AWT / Swing
    Replies: 1
    Last Post: 05-26-2011, 01:33 PM
  4. [SOLVED] JButton does not display ImageIcon properly
    By Singing Boyo in forum New To Java
    Replies: 1
    Last Post: 04-17-2009, 04:47 AM
  5. i cant dispose the jframe(urgent)
    By arunkumarinfo in forum NetBeans
    Replies: 2
    Last Post: 02-24-2009, 10:19 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts