Hello Guest

[FIXED] OSX Canvas in JInternalFrame draws to DesktopPane

  • 2 Replies
Hey guys,

I'm trying to port an applet from Windows to OSX. We use an applet with a JDesktopPane with a JInternalFrame, which holds the canvas. On windows, the canvas moves with the JInternalFrame. On OSX, the canvas seems to align to the JDesktopPane. The canvas does resize with the JInternalFrame, and they are registered as each others child/parent.

This example behaves as expected on Windows, but not on OSX:

Code: [Select]
import java.awt.Canvas;
import java.awt.Container;
import java.beans.PropertyVetoException;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.WindowConstants;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;

public class DesktopTest {

    public static void main(String[] args) {

        final JFrame frame = new JFrame();


        frame.setSize(500, 500);

        JDesktopPane desktop = new JDesktopPane();


        final JInternalFrame internalFrame = new JInternalFrame("internal!", true, true, false);


        internalFrame.setBounds(40, 40, 200, 150);
        try {
        } catch (PropertyVetoException e) {

        final Canvas canvas = makeCanvas();


        Thread invalidator = new Thread() {
            public void run() {
                while (true) {
                    //canvas.setLocation((int) internalFrame.getLocation().getX() + internalFrame.getInsets().left, (int) internalFrame.getLocation().getY() + internalFrame.getInsets().top);
        new Thread() {
         public void run() {
       try {


while(true) {
} catch (LWJGLException e) {
    public static void drawQuad() {

        GL11.glLoadIdentity(); // Resets any previous projection matrices
        GL11.glOrtho(0, 640, 480, 0, 1, -1);
     // clear the screen and depth buffer
        // set the color of the quad (R,G,B,A)
        // draw quad
    public static Canvas makeCanvas() {
        //Application app = new Application();
        //JmeCanvasContext context = (JmeCanvasContext) app.getContext();
        //Canvas canvas = context.getCanvas();
        Canvas canvas = new Canvas();
        return canvas;


EDIT: adjusted code to more clearly show canvas begin drawn (in)correctly
« Last Edit: July 23, 2013, 11:08:05 by orbitton »

Re: [BUG] OSX Canvas in JInternalFrame draws to DesktopPane
« Reply #1 on: August 08, 2013, 08:53:43 »
This issue is already reported http://lwjgl.org/forum/index.php/topic,4985.0.html, but so far no progress..


Offline kappa

  • *****
  • 1313
Re: [BUG] OSX Canvas in JInternalFrame draws to DesktopPane
« Reply #2 on: November 03, 2013, 14:08:46 »
This issue is now fixed and will be available in the next nightly builds of LWJGL 2.9.1.

Thanks for the test case was very useful in debugging this issue.

Main reason for the slew of bug fixes to OSX/CALayers recently is due to this JDK bug which Oracle will not be fixing until Java 8. Therefore we've had to implement a workaround for this bug on Java 7, CALayer positioning should work as normal on Java 6 and Java 8 onwards and not require use of the workaround code.
« Last Edit: November 03, 2013, 14:13:30 by kappa »