Sponsors: Michael Fertik - Best JAVA Web hosting Company & 30% off


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2010, 11:33 PM
Member
 
Join Date: Jan 2010
Posts: 81
Rep Power: 0
Psyclone is on a distinguished road
Default 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.

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);
And yes, I am intentionally using Absolute Positioning instead of a Layout Manager.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 02-07-2010, 11:46 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 8,431
Rep Power: 11
Fubarable is on a distinguished road
Default
You may be forgetting the JFrame's insets. Call getInsets on the JFrame and print it out to see what they are.

e.g.,
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();
      }
    });
  }
}
Myself, I would set the preferred size of the JFrame's contentPane not the JFrame itself.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-08-2010, 12:03 AM
Member
 
Join Date: Jan 2010
Posts: 81
Rep Power: 0
Psyclone is on a distinguished road
Default
OK, thanks. I think I set both of them.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting frame size to the size of an image Yoruichi AWT / Swing 5 04-22-2009 04:37 PM
Prob. with screen resolution and Frame size?? SANDY_INDIA AWT / Swing 1 08-16-2008 12:51 PM
[SOLVED] How to set the frame size? impact New To Java 7 05-02-2008 11:57 AM
Deploy Jar Side By Side Adrian Eclipse 0 04-11-2008 02:09 PM
Specifying absolute path in web.xml Felissa JavaServer Pages (JSP) and JSTL 1 07-05-2007 06:56 AM


Java Forums is supported by the best jsp hosting.

All times are GMT +2. The time now is 05:29 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org