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

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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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
    Posts
    22
    Rep Power
    0

    Default

    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 Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

Similar Threads

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