Results 1 to 6 of 6

Thread: Problem with setBounds settings

  1. #1
    Join Date
    Mar 2010
    Posts
    197

    Problem with setBounds settings

    Hello,
    I have a liite problem with my code
    I created a window in which I do the following

    Code:
    pn JPanel = new JPanel ();
    pn.setLayout (null);
    Then I add in the other two JPanel
    Code:
    jpne JPanel = new JPanel ();
    jpne.setBounds (0,0,200,400);
    jpne.add (new Panopticon ());
    pn.add (jpne);
    
    jpand JPanel = new JPanel ();
    jpand.setBounds (200,0,400,400);
    jpand.add (new pngr ());
    pn.add (jpand);
    
    pngr () and Panopticon () retrieve the width and height of their JPanel then displayed in the console. They look like:
    public class pngr extends JPanel (
    public void paintComponent (Graphics g) (
    lrg this.getWidth = int ();
    hutfen this.getHeight = int ();
    System.out.println (lrg + "" + hutfen + "\ n");
    Why setBounds settings are they not sent?
    Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    518

    Re: Problem with setBounds settings

    Hello,
    I think by default, JPanel uses FlowLayout that respects the "Preferred size". You can try to BorderLayout:
    Code:
    pan JPanel = new JPanel (new BorderLayout ());
    If you need more information on the swing concepts and all the classes and the methods which are included in the swing that is the awt package then you can visit the sun's official site and there you can find the API on the same.

  3. #3
    Join Date
    Dec 2009
    Posts
    211

    Re: Problem with setBounds settings

    Hello,
    I also have a similar kind of a problem with me. I placed "pn.setLayout (null)" in order to put myself elements, it seemed the easiest way to manage two objects. I followed your advice and added a BorderLayout and preferredSize. Unfortunately I get exactly the error there. If you have any alternative method or class which I can use to do the same, then it would be more helpful. Thanks in advance.

  4. #4
    Join Date
    Mar 2010
    Posts
    197

    Re: Problem with setBounds settings

    Hello,
    I have tried the following example, please check if I am in the correct direction
    Code:
    public class mnprg (
    public static void main (String [] args) (
    int wd = 200;
    int hg = 150;
    
    jfrm JFrame = new JFrame ();
    jfrm.setSize (wd, hg);
    jfrm.setLocationRelativeTo (null);
    jfrm.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    
    jpn JPanel = new JPanel ();
    jpn.setBounds (0,0, hg, hg);
    jpn.add (new PanPgr ());
    
    jfrm.setContentPane (jpn);
    jfrm.setVisible (true);
    }
    }

  5. #5
    Join Date
    Dec 2009
    Posts
    263

    Re: Problem with setBounds settings

    Hello,
    I am new to this concept but I have a code that could interest you, take a look at the code
    Here is the part of the code
    Code:
    public class prg extends JPanel (
    public void paintComponent (Graphics grp) (
    System.out.println (grp.getClipBounds ());
    grp.setColor (Color.BLUE);
    grp.fillRect (0, 0, 100, 100);
    }
    }

  6. #6
    Join Date
    Nov 2009
    Posts
    356

    Re: Problem with setBounds settings

    Hello,
    Check out the updated that is the modified form of the above code
    Code:
    Public class prg (
    
        Public static void main (Final String[] Args) (
    
            int w = 200;
    
            int hg = 150;
    
            JFrame jfrm = new JFrame ();
    
            jfrm.setSize (w, hg);
    
            jfrm.setLocationRelativeTo (null);
    
            jfrm.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    
            JPanel jpnl = new JPanel (new BorderLayout ());
    
            jpnl.add (new prg ());
    
            jfrm.setContentPane (jpnl);
    
            jfrm.setVisible (true);
    
        }
    
    }
    
    class prg extends JPanel (
    
        @ Override
    
        protected void paintComponent (Final Graphics grp) (
    
            System.out.println (grp.getClipBounds ());
    
            grp.setColor (Color.BLUE);
    
            grp.fillRect (0, 0, 100, 100);
    
        }
    
    }

Similar Threads

  1. Files and Settings Transfer Wizard Problem
    By Viensterrr in forum Windows XP Support
    Replies: 5
    Last Post: 06-10-2011, 03:22 AM
  2. W595 internet settings problem
    By Gillian Anderson in forum Portable Devices
    Replies: 4
    Last Post: 20-04-2010, 03:31 PM
  3. Problem of voltage settings
    By Badrunath in forum Hardware Peripherals
    Replies: 3
    Last Post: 05-10-2009, 10:07 PM
  4. Problem With Windows XP Network Settings
    By Dharamsi in forum Networking & Security
    Replies: 3
    Last Post: 17-03-2009, 11:17 PM
  5. Replies: 2
    Last Post: 13-11-2008, 11:51 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,715,679,029.59910 seconds with 17 queries