Results 1 to 3 of 3
  1. #1
    Psyclone is offline Member
    Join Date
    Jan 2010
    Posts
    81
    Rep Power
    0

    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.

    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);
    And yes, I am intentionally using Absolute Positioning instead of a Layout Manager.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    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.,
    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();
          }
        });
      }
    }
    Myself, I would set the preferred size of the JFrame's contentPane not the JFrame itself.

  3. #3
    Psyclone is offline Member
    Join Date
    Jan 2010
    Posts
    81
    Rep Power
    0

Similar Threads

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •