Results 1 to 10 of 10
  1. #1
    Cruncher is offline Member
    Join Date
    Mar 2010
    Posts
    88
    Rep Power
    0

    Default Bring component to front of a container?

    Okay well i don't understand why in java added components are sent to the back instead of the front, but is there a way i can bring a component to the front?

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

    Default

    I'm not sure I understand your question. Are you asking about Swing? Are you adding multiple components to a container so they overlap? What layout manager are you using? Do you want to use a JLayeredPane perhaps if you want to overlap components? For more help, please tell the details. Much luck.

  3. #3
    Cruncher is offline Member
    Join Date
    Mar 2010
    Posts
    88
    Rep Power
    0

    Default

    Using a JApplet.

    And I'm reprogramming my tetris game. Before it would save the coordinates of all the squares in a class that extends rectangle. But in the paint method when it repainted everything it would flicker.

    So now i'm trying to do it with labels, but the background label is the first one placed so every label I add after that goes underneathe it and you don't see anything.

  4. #4
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    You're not adressing the real problem here. Your applet flickers when repainting, because you draw an image, erase it to all white, then painting again. To overcome this problem, see a tutorial about double buffering.

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

    Default

    Quote Originally Posted by Cruncher View Post
    Using a JApplet.

    And I'm reprogramming my tetris game. Before it would save the coordinates of all the squares in a class that extends rectangle. But in the paint method when it repainted everything it would flicker.
    Yep as Moon states, your drawing is not using double buffering, and likely this is due to your painting in the paint method rather than in a JPanel's paintComponent method. You'll also want to do all your background painting in a BufferedImage and display that.

    So now i'm trying to do it with labels, but the background label is the first one placed so every label I add after that goes underneathe it and you don't see anything.
    Not sure what you're doing here.

  6. #6
    Cruncher is offline Member
    Join Date
    Mar 2010
    Posts
    88
    Rep Power
    0

    Default

    So wait, i'm not supposed to be overriding the paint method inside of JApplet?

    So what component am i supposed to be drawing in?

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

    Default

    Quote Originally Posted by Cruncher View Post
    So wait, i'm not supposed to be overriding the paint method inside of JApplet?
    Nope.


    So what component am i supposed to be drawing in?
    Create a JPanel and override its paintComponent method and then either add this JPanel to the applet's contentPane or make it the contentPane. I'd be surprised if you didn't see an improvement in your graphics by doing this.

  8. #8
    Cruncher is offline Member
    Join Date
    Mar 2010
    Posts
    88
    Rep Power
    0

    Default

    But doesn't a JApplet already have a set contentPane?

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

    Default

    Quote Originally Posted by Cruncher View Post
    But doesn't a JApplet already have a set contentPane?
    Yes, and you may use it to add your JPanel.

  10. #10
    Cruncher is offline Member
    Join Date
    Mar 2010
    Posts
    88
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Yes, and you may use it to add your JPanel.
    K, well thanks.

    Gonna look up double buffering and try to implement all of this later.

    I'll let you know how it works out.

Similar Threads

  1. Replies: 28
    Last Post: 09-15-2010, 10:21 AM
  2. Bring back the GOTO ;-)
    By rdtindsm in forum New To Java
    Replies: 5
    Last Post: 09-28-2009, 10:02 AM
  3. Replies: 3
    Last Post: 04-21-2009, 11:01 PM
  4. Front-End OOP Developer
    By AshleyNYC in forum Jobs Offered
    Replies: 0
    Last Post: 04-25-2008, 05:25 PM
  5. how to remove all component in container(Jpanel)
    By SaYuNaRa in forum New To Java
    Replies: 3
    Last Post: 04-17-2008, 04: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
  •