Results 1 to 4 of 4
  1. #1
    enerj is offline Member
    Join Date
    Sep 2010
    Posts
    30
    Rep Power
    0

    Default Sizing in an applet with subpanels - I want the subpanels to dictate the size

    Hello Gentlemen and Woman,
    I am working on an applet project for fun that I hope to share on the internet and can put here when I'm finished, I have already learned quite a bit and am only 10% along!

    Enough with the small talk, I want my applet to load 2 different panels, and these panels will most likely include their own panels, subpanels. I have toyed with what I want my layout to look like and it would be quite clean if the applet could run a border layout, and atleast 1 of my 2 panels could also run a border layout. Check the image here.

    Here is my relevant code, although I am not sure if this problem is even solvable using 2 borderlayouts. From my understanding so far, NORTH and SOUTH get their preferred heights, and EAST and WEST get their widths, and center get's whatever is left over. I basically want my most sub panels telling their adder their size, and the final applet size to be determined from this.

    Java Code:
    class ImageBackgroundPanel extends JPanel
    {
      Image image;
      private int width,height;
       
      public ImageBackgroundPanel()
      {
    	try
        {
          image = javax.imageio.ImageIO.read(new java.io.File("d:\\work\\misc work\\dyno app\\graph.jpg"));
        }
        catch (Exception e) { /*handled in paintComponent()*/ }
        
        width = image.getWidth(this);
        height = image.getHeight(this);
        //setPreferredSize(getDimension());
        setSize(getDimension());
        
      }
    Java Code:
    public class DynoAppletMain extends JApplet{
    
    ImageBackgroundPanel ibp2;
    	public void init(){
    		setLayout(new BorderLayout());
    		
    		ibp2 = new ImageBackgroundPanel();
    		//setSize(new Dimension(500,500));
    		
                    getContentPane().add(ibp2,BorderLayout.CENTER);
    				
    	}
    
    }
    I've got the setSize commented out, it works if I do that, even if I pull the dimension from the ibp2 object, but that's not what I want to do, if avoidable. Also, is getting the content pane necessary for an applet? I've used it with frames, and seen it in applet code, so I use it.

    ABOUT THE IMAGE - for the applet borderlayout I just need 2 of the 5 sections, I am not planning on using west for anything, not that it really matters. Any help appreciated guys!
    Attached Thumbnails Attached Thumbnails Sizing in an applet with subpanels - I want the subpanels to dictate the size-layout.jpg  

  2. #2
    enerj is offline Member
    Join Date
    Sep 2010
    Posts
    30
    Rep Power
    0

    Default

    hrmm I am interpreting the lack of replies as a sign that my solution my not be down the double border panel path. I am going to experiment with box layout and some others, I'll give word here if I have better luck.

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

    Default

    Quote Originally Posted by enerj View Post
    Here is my relevant code, although I am not sure if this problem is even solvable using 2 borderlayouts. From my understanding so far, NORTH and SOUTH get their preferred heights, and EAST and WEST get their widths, and center get's whatever is left over. I basically want my most sub panels telling their adder their size, and the final applet size to be determined from this.
    Per my understanding of applets (which is admittedly limited), the final applet size is determined by the HTML code that's calling it, not by the components it holds, the layouts it uses, or any setSize or setPreferredSize calls within it.

  4. #4
    enerj is offline Member
    Join Date
    Sep 2010
    Posts
    30
    Rep Power
    0

    Default

    Most of the panels/objects size in my applet will be determined upon compile time, however I want the applet to be able to take in an image from the user (another issue for another time =] ).

    Do you think I should make the applet resize this image upon loading to a maximum allowable so that the size of the applet is always fixed and I can represent this in my HTML tags? I think this is the cleanest solution.

Similar Threads

  1. Panel sizing
    By sjs in forum AWT / Swing
    Replies: 5
    Last Post: 10-11-2010, 03:13 AM
  2. Changing default Applet Viewer Size?
    By dsym@comcast.net in forum Java Applets
    Replies: 6
    Last Post: 08-27-2010, 06:42 PM
  3. Applet JTextField Size Problem
    By a13w in forum New To Java
    Replies: 4
    Last Post: 09-19-2009, 07:52 AM
  4. Replies: 4
    Last Post: 02-22-2009, 06:31 AM
  5. Help needed with sizing components
    By adlb1300 in forum New To Java
    Replies: 2
    Last Post: 11-20-2007, 04:40 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
  •