import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Color; import java.awt.MenuItem; import java.awt.MouseInfo; import java.awt.PopupMenu; import java.awt.event.ActionEvent; import java.beans.PropertyVetoException; import javax.swing.AbstractAction; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JToolBar; import javax.swing.LookAndFeel; import javax.swing.SwingUtilities; import javax.swing.UIManager; import com.jogamp.opengl.awt.GLCanvas; import com.jogamp.opengl.awt.GLJPanel; public class TestInternalFrameCanvas { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { showUI(); } }); } private static void showUI() { // put metal look and feel to avoid shadows effects and custom OSX // behavior. try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // desktop pane JDesktopPane pane = new JDesktopPane(); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(pane, BorderLayout.CENTER); // simple toolbar JToolBar tb = new JToolBar(); tb.add(new AbstractAction("Test") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { PopupMenu menu = new PopupMenu(); pane.add(menu); menu.add(new MenuItem("Just a heavy popup test menu")); menu.show(pane, 200,400); } }); frame.getContentPane().add(tb, BorderLayout.WEST); // first internal frame contains a single JPanel (yellow bg) JInternalFrame iframe0 = new JInternalFrame("Test jpanel", true, true, true, true); iframe0.setSize(400, 400); iframe0.setLocation(0, 0); JPanel p = new JPanel(); p.setBackground(Color.yellow); iframe0.getContentPane().add(p); iframe0.setVisible(true); // second internal frame contains a GLCanvas JInternalFrame iframe1 = new JInternalFrame("Test GLCanvas", true, true, true, true); iframe1.setSize(400, 400); iframe1.setLocation(450, 0); GLCanvas c = new GLCanvas(); iframe1.getContentPane().add(c); // third internal frame contains a standard AWT Canvas. JInternalFrame iframe2 = new JInternalFrame("Test AWT Canvas", true, true, true, true); iframe2.setSize(400, 400); iframe2.setLocation(0, 450); Canvas c2 = new Canvas(); c2.setBackground(Color.pink); iframe2.getContentPane().add(c2); // last internal frame contains a GLJPanel. JInternalFrame iframe3 = new JInternalFrame("Test GLJPanel", true, true, true, true); iframe3.setSize(400, 400); iframe3.setLocation(450, 450); GLJPanel p2 = new GLJPanel(); p2.setBackground(Color.green); iframe3.getContentPane().add(p2); try { iframe0.setVisible(true); iframe1.setVisible(true); iframe2.setVisible(true); iframe3.setVisible(true); iframe1.setSelected(true); pane.add(iframe0); pane.add(iframe1); pane.add(iframe2); pane.add(iframe3); } catch (PropertyVetoException e) { // TODO Auto-generated catch block e.printStackTrace(); } frame.setSize(800, 800); frame.setVisible(true); } }