Results 1 to 4 of 4
  1. #1
    AedonetLIRA is offline Member
    Join Date
    Oct 2010
    Rep Power

    Default 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.

    Java 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");
    	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));
    Last edited by AedonetLIRA; 12-02-2010 at 03:58 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    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.

  3. #3
    AedonetLIRA is offline Member
    Join Date
    Oct 2010
    Rep Power


    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.

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

Similar Threads

  1. When to use setSize()
    By Lil_Aziz1 in forum New To Java
    Replies: 7
    Last Post: 05-29-2010, 04:26 PM
  2. Why is my Do/While Not working?
    By Meta in forum New To Java
    Replies: 1
    Last Post: 05-11-2010, 07:05 PM
  3. working with JC
    By yuhobebbho in forum New To Java
    Replies: 0
    Last Post: 02-11-2010, 12:22 AM
  4. [Help] setSize work wrong ???
    By dawp in forum New To Java
    Replies: 7
    Last Post: 11-05-2009, 10:30 AM
  5. Replies: 8
    Last Post: 05-28-2008, 08:00 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