Results 1 to 5 of 5
  1. #1
    TaintedMike is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Positioning objects within a JApplet.

    So, i'm making a JApplet and using swing graphics.
    I'm not 100% sure how to make a custom Layout and set the objects to a specific point like (534,545).
    Each time i do
    Java Code:
    Item1.setLocation(0,0);
    It just doesn't display the object I'm trying to display.

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

    Default Re: Positioning objects within a JApplet.

    It's usually not a good idea to set the exact position of components within a GUI. Rather you're much better off using layout managers and letting them set the component position and size for you.

  3. #3
    TaintedMike is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: Positioning objects within a JApplet.

    okay, but it is possible right? and if it was setting why does it not show up at all or sometimes stack at the top when i have the positions set?

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

    Default Re: Positioning objects within a JApplet.

    To do this, you must set the layout of the container that holds the components to null. If you do this, then you the programmer are fully responsible for setting the position and size of all components added to this container.

    But having said this, while at first it seems easiest to make all layouts null and simply specify where each component should go, in the long run this will make creating and maintaining the GUI a nightmare. Image a complex GUI that holds 4 JRadioButtons in a column in the middle of the GUI. Now imagine that on revision you must add one more JRadioButton. This will mean not only setting it's position and size, but adjusting all components below and to the right of it with a huge risk of side effect. If on the other hand you used simple layouts nested in each other, you would only need one line of code with a minuscule risk of side effect.
    Last edited by Fubarable; 01-30-2012 at 04:55 AM.

  5. #5
    TaintedMike is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: Positioning objects within a JApplet.

    Ok, thanks.
    Btw i think ill just stick with normal programs no more applets.

Similar Threads

  1. A componenet positioning problem
    By apprerntice in forum AWT / Swing
    Replies: 10
    Last Post: 07-22-2011, 07:53 PM
  2. Vertical box and positioning
    By aborgeld in forum New To Java
    Replies: 9
    Last Post: 04-01-2011, 07:33 PM
  3. Positioning using setBounds
    By thayalan in forum AWT / Swing
    Replies: 4
    Last Post: 04-28-2009, 01:59 AM
  4. JFrame to JApplet or JApplet to JApplet
    By ramesh.8189 in forum AWT / Swing
    Replies: 13
    Last Post: 02-08-2009, 06:14 AM
  5. panel positioning
    By shwein in forum New To Java
    Replies: 4
    Last Post: 09-09-2008, 05:15 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
  •