Results 1 to 3 of 3
- 02-07-2010, 11:33 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 81
- Rep Power
- 0
Frame size clipping pixels off right side with Absolute Positioning
I made a frame that is 1280x800. I'm using Absolute Positioning and when I add a panel or label that is 1280 pixels wide, it doesn't show about 8 pixels on the right side.
Why is the frame drawing at only 1272 pixels wide? I don't think it's the panel drawing at the wrong size, because I also have multiple panels across the middle and bottom of the frame that are lining up properly with the top panel.
And yes, I am intentionally using Absolute Positioning instead of a Layout Manager.Java Code:JFrame lobbyFrame = new JFrame("Welcome to ..."); lobbyFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); lobbyFrame.setSize(1280, 800); JPanel lobbyPanelTop = new JPanel(); lobbyFrame.add(lobbyPanelTop); lobbyPanelTop.setLayout(null); lobbyPanelTop.setOpaque(true); lobbyPanelTop.setBackground(new Color(202, 102, 202)); lobbyPanelTop.setPreferredSize(new Dimension(1280, 120)); Dimension size = lobbyPanelTop.getPreferredSize(); lobbyPanelTop.setBounds(0, 0, size.width, size.height);
-
You may be forgetting the JFrame's insets. Call getInsets on the JFrame and print it out to see what they are.
e.g.,
Myself, I would set the preferred size of the JFrame's contentPane not the JFrame itself.Java Code:import java.awt.Dimension; import javax.swing.*; public class FuSwing { private static final Dimension SIZE = new Dimension(400, 400); private static void createAndShowUI() { JPanel panel = new JPanel(); JFrame frame = new JFrame("FuSwing"); frame.setPreferredSize(SIZE); frame.getContentPane().add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); System.out.println(panel.getSize()); System.out.println(frame.getInsets()); } public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { createAndShowUI(); } }); } }
- 02-08-2010, 12:03 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 81
- Rep Power
- 0
Similar Threads
-
Setting frame size to the size of an image
By Yoruichi in forum AWT / SwingReplies: 5Last Post: 04-22-2009, 04:37 PM -
Prob. with screen resolution and Frame size??
By SANDY_INDIA in forum AWT / SwingReplies: 1Last Post: 08-16-2008, 12:51 PM -
[SOLVED] How to set the frame size?
By impact in forum New To JavaReplies: 7Last Post: 05-02-2008, 11:57 AM -
Deploy Jar Side By Side
By Adrian in forum EclipseReplies: 0Last Post: 04-11-2008, 02:09 PM -
Specifying absolute path in web.xml
By Felissa in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 07-05-2007, 06:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks