Results 1 to 9 of 9
Thread: JFrame.pack() leaves 10px margin
- 01-28-2012, 01:40 AM #1
Senior Member
- Join Date
- Jan 2009
- Location
- NJ, USA
- Posts
- 183
- Rep Power
- 5
- 01-28-2012, 01:44 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: JFrame.pack() leaves 10px margin
That would be good - a SSCCE which creates a frame and a panel, adds the panel to the frame then packs and displays the frame.I can provide code if necessary.
Also, this is really a Swing question: I'll move it to the AWT/Swing forum.
- 01-28-2012, 01:48 AM #3
Senior Member
- Join Date
- Jan 2009
- Location
- NJ, USA
- Posts
- 183
- Rep Power
- 5
Re: JFrame.pack() leaves 10px margin
Okay, I included the constructors which might be useful below. Also, the full file is here:
privatepaste.com :: Paste ID e905cab22c

Java Code:... public Client(String title, int width, int height) { FPS = 0; WIDTH = width; HEIGHT = height; mouseX = mouseY = 0; input = new HashMap<String, Boolean>(); updates = new ArrayList<Updatable>(); renders = new ArrayList<Renderable>(); setBackground(Color.BLACK); setTitle(title); panel = new ClientPanel(this, width, height); add(panel); pack(); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); panel.addMouseListener(this); panel.addMouseMotionListener(this); } ... public ClientPanel(Client client, int width, int height) { this.client = client; WIDTH = width; HEIGHT = height; setFocusable(true); requestFocus(); setBackground(Color.BLACK); setPreferredSize(new Dimension(WIDTH, HEIGHT)); period = 20; }Last edited by AndrewM16921; 01-28-2012 at 01:57 AM.
- 01-28-2012, 02:11 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: JFrame.pack() leaves 10px margin
Did you read the SSCCE link?
You are getting a 10px margin because somewhere within your code you are setting such a margin. The problem is, therefore, to remove things that are not relevant in order to reveal where this margin setting is taking place. That is the strategy suggested by the SSCCE and it is particularly successful: many times you will solve a problem just by revealing it. If you are unsuccessful then you still win because you have code that will be clear to others who might want to look at it.
As it is, people are rather reluctant to download code and undertake, on your behalf, the task of separating what is part of the problem and what is distracting context. More so if there are several hundred lines of code including dependencies on other classes not given which, together, define a class which is ... abstract!
-----
I realise that constructing a SSCCE takes work, but that's the point. It's productive work if it reveals what needs to change.
- 01-28-2012, 02:24 AM #5
Senior Member
- Join Date
- Jan 2009
- Location
- NJ, USA
- Posts
- 183
- Rep Power
- 5
Re: JFrame.pack() leaves 10px margin
Yeah, I'm familiar with the SSCCE thing. I chopped it up and the problem doesn't persist, but I can't seem to isolate what's causing it so I'm working on that at the moment.
- 01-28-2012, 02:35 AM #6
Senior Member
- Join Date
- Jan 2009
- Location
- NJ, USA
- Posts
- 183
- Rep Power
- 5
Re: JFrame.pack() leaves 10px margin
Okay, this is weird. Can the setVisible() method change the size...?
printed thisJava Code:System.out.println(panel.getSize().toString()); setVisible(true); System.out.println(panel.getSize().toString());
java.awt.Dimension[width=900,height=700]
java.awt.Dimension[width=910,height=710]
Right well, I fixed it by moving the pack() to the end. Solved.Last edited by AndrewM16921; 01-28-2012 at 02:40 AM.
-
Re: JFrame.pack() leaves 10px margin
Possibly. Where's your SSCCE?
- 01-28-2012, 03:05 AM #8
Member
- Join Date
- Sep 2011
- Posts
- 37
- Rep Power
- 0
Re: JFrame.pack() leaves 10px margin
You want to do the set visible and set resizible befor packing
- 01-28-2012, 04:38 AM #9
Similar Threads
-
What am I doing wrong? Shrinking circle leaves a smear.
By rhexis in forum New To JavaReplies: 3Last Post: 12-07-2011, 10:59 PM -
recursive directories deletion leaves random files
By Jovaras in forum New To JavaReplies: 11Last Post: 05-27-2011, 10:29 AM -
Two calls to JFrame.pack() required to get desired effect?
By dark_perfect in forum AWT / SwingReplies: 1Last Post: 03-24-2011, 01:03 AM -
PDF Printing - Margin Problem
By faoilean in forum Advanced JavaReplies: 0Last Post: 01-24-2011, 10:15 AM -
Using frame.pack() for resizing JFrame
By LianaN in forum AWT / SwingReplies: 0Last Post: 10-30-2010, 12:12 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks