Results 1 to 6 of 6
  1. #1
    jboy is offline Member
    Join Date
    Aug 2009
    Posts
    56
    Rep Power
    0

    Default how to set the location of a panel?

    Hi,

    I am using panel.setLocation(int, int); in my program but it doesn't affect anything, is there any other method that can help me change the location of a panel within another larger panel?

    Thanks.

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    828
    Rep Power
    6

    Default

    Could u send the code withj codetag so that we can see and give solution?
    Ramya:cool:

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

    Default

    The best way to set the location of JPanels and other components is to let the layout managers do the heavy lifting for you. I recommend (if you haven't done so already) that you have a look at the layout manager tutorials. Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)

  4. #4
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    Hello,
    true Furable is right!!!

    you could try using : FlowLayout, GridLayout, BoxLayout They are easy to use.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default

    ... on the other hand: suppose the OP wants to create a card game where the cards (JPanels with an image) float around freely in their parent container. Remove the LayoutManager from the parent container and whenever a JPanel is repositioned call revalidate() on it.

    kind regards,

    Jos

  6. #6
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    Remove the LayoutManager from the parent container and whenever a JPanel is repositioned call revalidate() on it.
    Only component using LayoutManagers require the use of revalidate(). If you don't use a LayoutManager then you are responsible for setting the size/location of the component. That is why the recommendation is to always use a layout manager so you can invoke revalidate() and you don't have to worry about all the minor details.

Similar Threads

  1. location provider returns no location
    By sandeeprao.techno in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-24-2009, 09:54 AM
  2. File Location
    By bcbird in forum New To Java
    Replies: 1
    Last Post: 09-17-2009, 08:03 AM
  3. weird location of ovals
    By diggitydoggz in forum New To Java
    Replies: 6
    Last Post: 12-24-2008, 12:25 AM
  4. how to get the location of some button
    By mary in forum Java 2D
    Replies: 2
    Last Post: 08-05-2007, 04:02 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
  •