Results 1 to 4 of 4
- 11-10-2010, 04:39 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 30
- Rep Power
- 0
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()); }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.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); } }
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!
- 11-10-2010, 11:11 PM #2
Member
- Join Date
- Sep 2010
- Posts
- 30
- Rep Power
- 0
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.
-
- 11-11-2010, 02:14 AM #4
Member
- Join Date
- Sep 2010
- Posts
- 30
- Rep Power
- 0
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
-
Panel sizing
By sjs in forum AWT / SwingReplies: 5Last Post: 10-11-2010, 03:13 AM -
Changing default Applet Viewer Size?
By dsym@comcast.net in forum Java AppletsReplies: 6Last Post: 08-27-2010, 06:42 PM -
Applet JTextField Size Problem
By a13w in forum New To JavaReplies: 4Last Post: 09-19-2009, 07:52 AM -
what is that method to change the size of a font in an applet?
By javanoobita in forum New To JavaReplies: 4Last Post: 02-22-2009, 06:31 AM -
Help needed with sizing components
By adlb1300 in forum New To JavaReplies: 2Last Post: 11-20-2007, 04:40 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks