How to force JPanel to expand the same size as JFrame
843807May 13 2010 — edited May 13 2010Hi All...
I am just started swing...
I have created a JPanel, which contain a GLDrawable.
Then I cerated a JFrame with a specific size, and added to the JFrame the JPanel.
When execute the program, it seems that the JPanel not capture the all size of JFrame.
Can you explain me how to expand the JPanel.
Many thanks for the help
YyYo.
here is the code
package Designer;
import java.awt.BorderLayout;
import javax.swing.*;
import javax.media.opengl.*;
public class DrawingArea extends JPanel{
private GLJPanel drawingCanvas;
public DrawingArea(){
GLCapabilities caps = new GLCapabilities();
caps.setDoubleBuffered(true);
drawingCanvas = new GLJPanel(caps);
drawingCanvas.setSize(200, 400);
drawingCanvas.addGLEventListener((new GLEventCanvasListener()));
add(drawingCanvas);
setSize(200,400);
}
public static void main(String argv[]){
JFrame myFrame = new JFrame("Drawing area");
myFrame.setVisible(true);
myFrame.setSize(200,400);
myFrame.getContentPane().add(new DrawingArea(),BorderLayout.CENTER);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.getContentPane().add(new JLabel("my label"),BorderLayout.EAST);
}
}
package Designer;
import javax.media.opengl.*;
public class GLEventCanvasListener implements GLEventListener{
public void init(GLAutoDrawable drawable){
System.out.println("init method");
GL gl = drawable.getGL();
gl.glClearColor(0,0,0,0);
}
public void display(GLAutoDrawable drawable){
System.out.println("display method");
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
}
public void reshape(GLAutoDrawable drawable,
int x,
int y,
int width,
int height){
System.out.println("reshape method");
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){
System.out.println("displayChanged method");
}
}