Results 1 to 4 of 4
  1. #1
    manibby93 is offline Member
    Join Date
    Sep 2013
    Posts
    77
    Rep Power
    0

    Default frame.setResizable(false) changes window size instead of keeping dimensions?? Help?

    Java Code:
    frame.setResizable(false);
    It makes my JFrame for my Calculator class unresizable (not a word), but it adds a few pixels within the frame, on the bottom and right sides... or removes some from a panel or two. Idk. Just look. Hopefully someone helps me this time...

    frame.setResizable(false) changes window size instead of keeping dimensions?? Help?-calc.jpg

    Java Code:
    public class TestCalculator {
    
      public static void main(String[] args) {
    
            ImagePanel panel = new ImagePanel(new ImageIcon("01_Crane_AGweb.jpg").getImage());
            
            SimpleArithmeticCalculator calc = new SimpleArithmeticCalculator();
    
            JFrame frame = new JFrame("Simple Arithmetic Calculator");
            
            frame.setResizable(false);   
    
            frame.getContentPane().add(panel);
            
            frame.getContentPane().add(calc);
            
            frame.setPreferredSize(new Dimension(358,379));
            
            frame.pack();
            
            frame.setVisible(true);      
            
            frame.setMinimumSize(new Dimension(358,379));
            
            frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        
            panel.setVisible(true);
                    
            panel.setOpaque(true);
            
            panel.add(calc);
               
            calc.SetColors(null , Color.white , new Color(72,61,139));
        
            calc.setVisible(true);
    
            calc.setOpaque(false);
            
    }
        
    }
    
    class ImagePanel extends JPanel {
    
      private Image img;
    
      public ImagePanel(String img) {
    
        this(new ImageIcon(img).getImage());
      
      }
    
      public ImagePanel(Image img) {
      
        this.img = img;
            
        Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
        
        this.setPreferredSize(new Dimension(size));
        
        this.setMinimumSize(new Dimension(size));
        
        this.setMaximumSize(new Dimension(size));
        
        this.setSize(new Dimension(size));
        
        this.setLayout(null);
      
      }
    
        public void paintComponent(Graphics g) {
          
            super.paintComponent(g);
            
            g.drawImage(img, 0, 0, this.getWidth(),this.getHeight(),this);
            
        }
    
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default Re: frame.setResizable(false) changes window size instead of keeping dimensions?? Hel

    I don't know if it solves your problem but you can add a Component to only one Container; you're violating that rule with at least the calc component (first you add it to a ContentPane and next you add it to a panel ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    manibby93 is offline Member
    Join Date
    Sep 2013
    Posts
    77
    Rep Power
    0

    Default Re: frame.setResizable(false) changes window size instead of keeping dimensions?? Hel

    If I don't add it to the panel, it won't show up. The same if I take it out of the ContentPane & add it to a panel. It'll just show the background.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default Re: frame.setResizable(false) changes window size instead of keeping dimensions?? Hel

    Quote Originally Posted by manibby93 View Post
    If I don't add it to the panel, it won't show up. The same if I take it out of the ContentPane & add it to a panel. It'll just show the background.
    You're doing something wrong then: the content pane should be the root of a tree; further nodes are your panel(s) and buttons, but they all should be added to one parent only.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 7
    Last Post: 05-30-2013, 06:17 PM
  2. Keeping the dimensions of a JPanel.
    By willemien in forum AWT / Swing
    Replies: 13
    Last Post: 03-06-2013, 09:17 AM
  3. Replies: 7
    Last Post: 05-26-2012, 07:07 PM
  4. Keeping one window above another
    By porchrat in forum AWT / Swing
    Replies: 3
    Last Post: 01-27-2011, 08:11 AM
  5. Replies: 4
    Last Post: 01-18-2011, 08:22 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
  •