Results 1 to 5 of 5
  1. #1
    thayalan is offline Member
    Join Date
    Feb 2009
    Posts
    11
    Rep Power
    0

    Default Positioning using setBounds

    Hello there,

    i am creating JTextField and JComboBox inside a painted rectangle on a panel. The location for JTextField and JComboBox is set using the setBounds method. However, everytime the frame is maximized or resized, both the JTextField and JComboBox get repositioned to the top middle of the frame. Could you advice why it happens and how do i update new coordinate values for those components should i want to reposition them.

    Thanks.

  2. #2
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    before setting the position of everything, use setLayout(null)
    I die a little on the inside...
    Every time I get shot.

  3. #3
    thayalan is offline Member
    Join Date
    Feb 2009
    Posts
    11
    Rep Power
    0

    Default

    I tried it already but it's not working. To give you some more info,
    Jtxtfld is located in myPanel which is an instance of CustomPanel. Once myPanel is instantiated, its added to the container class without specifying the layout. During the instantiation of JTxtFld, just before setBound method is invoked, JTxtFld.setlayout(null) was invoked. Pls advice if that is what you meant in ur response earlier. Thanks.

  4. #4
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    You need to call setLayout(null) on the container before you add any components to it.

    You need to call validate() on the container after you have added all the components.

    Finally though, don't position your components this way, use the provided LayoutManagers, they can create any layout you wish
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  5. #5
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    I just wanted to agree with what O.D. said. The layout managers are a pain in the rear to figure out, but they work well once you understand them.

Similar Threads

  1. Using setBounds (x.y,width,height) constructor
    By hitmen in forum AWT / Swing
    Replies: 3
    Last Post: 03-06-2009, 01:12 PM
  2. I obviously don't understand positioning panels
    By javatard in forum New To Java
    Replies: 2
    Last Post: 12-10-2008, 08:48 AM
  3. panel positioning
    By shwein in forum New To Java
    Replies: 4
    Last Post: 09-09-2008, 06:15 PM
  4. Problem here guys: Set location or setBounds
    By themburu in forum New To Java
    Replies: 3
    Last Post: 06-03-2008, 08:19 PM

Posting Permissions

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