aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Size of frame problem /XP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Size of frame problem /XP" Watch "Size of frame problem /XP" New topic
Author

Size of frame problem /XP

Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
One of users is experiencing a strange problem where a pop up window pops up really small. To be exact the first time it pops up, it's really big and on subsequent occasions, it's really small.
The pop up is implemented by a JFrame. The usage is quite strange (well it is to me anyway ). JFrame instances are reused and the content is changed via creating a new JPanel and calling setContentPane.
Anyway I digress, the weird thing about this problem is that it only affects this one user. It started affecting him when we migrated him to XP. We have other users on XP and they do not have this problem.
I first thought that the problem was that the JFrame was not being packed, so I overided setVisible to always call pack before setVisible, however this did not help.
I then added some extra logging to see if I could see what was going on. I added the following :

This threw up some things that confused me. Check the output here
2 things struck me as strange.
1. A call to pack does not make the frames size equal to it's preferred size.
2. Before packing the frame has more components on it's content pane than after. There is no multi-threading going on.
If anyone could help shed some light on this issue, or perhaps advise me where else to look/what else to look or any help at all, it would be very much appreciated.
thanks,
Don
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Sorry, but the resolution on the image is so bad that I can't read what is circled and supposed to be weird about it...

I think the direpency between preferred size and actual size is because the title bar affects this also. I think the title bar minimum size is actually calculated in AWT native code, so the JFrame itself doesn't take this into account when it calculates its preferred size. If you want to see how this affects things call JFrame.setDefaultLookAndFeelDecorated( true ) before you create the frame (this will use Java generated title bars and will truely reflect preferred size) or add padding around the widgets you are adding to the frame to get it larger than the minimum size of the title bar.

Take a look for widgets being added to the content pane in the frame's constructor (or methods called from the constructor) and if the frame doesn't directly subclass JFrame, look in parent classes constructors.

Does the user have the same problem now that you have added the pack() in? Are there any other things that are different between this user's setup and other users? JVM version, video card, etc. One thing I would especially look for in this case would be different screen resolutions... If they weren't using pack, they might have just set the frame to a specific pixel size somewhere. This size might be OK for everyone running the program at 1280 x 1024, but the frame is going to be double the size for anyone running it at 640 x 480!


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
Sorry, but the resolution on the image is so bad that I can't read what is circled and supposed to be weird about it...
Having major difficulties making it big enough, if I make the image bigger, yahoo just shrinks it.
Can you see this


I think the direpency between preferred size and actual size is because the title bar affects this also. I think the title bar minimum size is actually calculated in AWT native code, so the JFrame itself doesn't take this into account when it calculates its preferred size. If you want to see how this affects things call JFrame.setDefaultLookAndFeelDecorated( true ) before you create the frame (this will use Java generated title bars and will truely reflect preferred size) or add padding around the widgets you are adding to the frame to get it larger than the minimum size of the title bar.
This wouldn't explain a pre-pack preferred size of (508, 296) to a post-pack size of (112, 98) though. I'll give it a try anyway though.

Take a look for widgets being added to the content pane in the frame's constructor (or methods called from the constructor) and if the frame doesn't directly subclass JFrame, look in parent classes constructors.

No construction is done in this, super or subclasses of this class.

Does the user have the same problem now that you have added the pack() in?

Yes, no change in behaviour.

Are there any other things that are different between this user's setup and other users? JVM version, video card, etc. One thing I would especially look for in this case would be different screen resolutions... If they weren't using pack, they might have just set the frame to a specific pixel size somewhere. This size might be OK for everyone running the program at 1280 x 1024, but the frame is going to be double the size for anyone running it at 640 x 480!
I agree, there must be something specific to this user that's causing the problem. JVM is the same, video card is the same. So I'm not sure what it is.
I'm fairly sure setSize isn't being called, I'll overide it and log usage to check that is the case.
thanks for your help
D.
[ October 27, 2003: Message edited by: Don Kiddick ]
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
Bump
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

You wouldn't be looking for setSize() on the frame itself, but for a setPreferredSize() on a component being added to it. If you track down where those "mystery components" are being added you will probably find the source of the problem. Override all the add() methods to print out when they are called and you should be able to track this down.
I see even more odd output on the printout you've posted a link to. The preferred size of the frame after the pack() is same as before the pack() even though the actual size is different... that really shouldn't be happening.

The full print out would probably be too long to post here, or get in a readable format posted as a picture... could you email me a printout of a run from the start? I'd like to see the very first message that this prints out... you can get my email address by clicking on the "flying mail" icon above this post.
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
Nate/All, just a quick update. I have found that the mystery components being added were down to my dodgy logging code. In the post-pack code my loop uses getComponentCount() rather than getContentPane().getComponentCount(). I still have the problem that after a pack() my frames size != it's prefferred size, it's not even close.
From my logging :
after pack size: 112, 98
after pack prefferred size: 500, 110
This seems strange to me. As I understand it, this shouldn't happen. Maybe I should overide the pack method to make sure this is definitely true.
As for sending the full output, that's not currently possible, as I'm just logging to a JList at the moment. I did write a nice LogPanel about a year ago, I might try and locate and use that.... anyways I don't have much time to spend on this today but I should do tomorrow and I will give an update then.
thanks,
D.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Size of frame problem /XP
 
Similar Threads
Printing and Preview of Nested JTable not working and performance is slow....
setVisible takes too long to return
Java text fields on a panel in a 2d array
Event dispatch thread
JFrame.setSize() calls ignored until after JFrame.show()