Results 1 to 3 of 3
- 03-13-2011, 02:32 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 5
- Rep Power
- 0
Please explain to where container dimensions come from
Hi,
Well, I'm finally painting my JPEGs to the screen. I've got a question though about where the containers dimensions come from. I was using an example from a previous post to this group actually. I've extened JPanel with my own panel and the constructor looks like this:
public PhotoViewer(BufferedImage bi) {
mBuffImg = bi;
mPanelSize = new Dimension(bi.getWidth(), bi.getHeight());
}
My PhotoViewer panel had dimensions of 0x0 until I overrode the getWidth() and getHeight() methods. What seems odd to me is why this would be because that mPanelSize member field is being returned by my overridden getPreferredSize() method in this container. I thought that perhaps I should call the setPreferredSize() method in my ctor, but this didn't have any affect until I overrode getWidth() and getHeight().
Why is this?
Thanks,
Andy
-
You will likely want to set the preferredSize of the JPanel since most layout managers will use this to decide how to size the component. It may not work because you are not using layout managers, or not using layout managers that honor the preferredSize, or are not packing your gui before setting it visible.
Last edited by Fubarable; 03-13-2011 at 03:19 AM.
- 03-13-2011, 04:29 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 5
- Rep Power
- 0
I'm using NetBeans for development and am not, at this point, using layout managers directly. I assumed that NetBeans had put that in there for me and was managing it. Is this a bad assumption?
Your last statement has me intrigued. Again, I've been letting NetBeans manage the work of displaying the GUI. In all of the example code I've seen from the myriad of places I've been to looking for help, I've always seen calls to pack() before setting visible to true. Again, because I am using NetBeans, I assumed that this was being done for me. Is this too a bad assumption? Should the container always be packed if something is added to it? That is, even if it's already been displayed once before?
Andy
Similar Threads
-
Please Explain me how i got this output.. I am new to java .. so please Explain me...
By vicky82 in forum New To JavaReplies: 2Last Post: 12-13-2010, 01:34 PM -
Please Explain me how i got this output.. I am new to java .. so please Explain me...
By vicky82 in forum New To JavaReplies: 3Last Post: 12-13-2010, 07:22 AM -
[SOLVED] Coordinates container --> in parent container.
By Cleite in forum AWT / SwingReplies: 3Last Post: 04-21-2009, 11:01 PM -
How can i get image dimensions using java?
By Thilkumar82 in forum Advanced JavaReplies: 0Last Post: 09-02-2008, 09:12 AM -
how to set full screen dimensions
By valery in forum New To JavaReplies: 1Last Post: 08-03-2007, 06:08 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks