-
setSize() not working?
I need a JPanel to be the given size. The applet starts at 200x200 but then expands to the correct size; however the JPanel never resizes to the correct size... I have looked everywhere for the solution to the this, and they all say the same thing, "Use setPreferredSize instead of setSize". I have done this and it still doesn't work... Any help will be sooo helpful.
Code:
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import javax.swing.JApplet;
public class Applet extends JApplet {
/**
*
*/
private static final long serialVersionUID = 1L;
public static final int DEFAULT_FPS = 80;
private World mWorld;
//private JTextField mFPS;
public void init() {
this.setPreferredSize(new Dimension(1200, 800));
String str = getParameter("fps");
int fps = (str != null) ? Integer.parseInt(str) : DEFAULT_FPS;
long period = (long) 1000.0/fps;
System.out.println("fps: "); //+ fps + "; period: " + period + " ms");
makeGUI();//period);
}
private void makeGUI() {//long period) {
Container c = getContentPane();
c.setLayout(new BorderLayout());
// World Extends JPanel
mWorld = new World(this);
mWorld.setMinimumSize(new Dimension(1200, 800));
mWorld.setPreferredSize(new Dimension(1200, 800));
c.add(mWorld);
}
}
-
I don't really do applet coding, but as far as I understand it, the applet size is set by the HTML code calling the applet, not by the applet itself.
-
As I understand it, that is true, but all of the frames inside of the applet are not. It's the JPanel inside that I'm struggling with.
-