Results 1 to 5 of 5
  1. #1
    Join Date
    May 2011
    Location
    Maryland
    Posts
    38
    Rep Power
    0

    Default Overlapping JLabels

    How can I get two JLabels (with images inside them) to overlap each other? If it helps, I am working on a monopoly project in which I have an image of the board space as one JLabel and an image of the game piece as another JLabel. When the piece lands on the space I want it to place the image ON TOP of the board space image. Is this at all possible? Any help is appreciated

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

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

    Default

    I am working on a monopoly project in which I have an image of the board space as one JLabel and an image of the game piece as another JLabel.
    You can add another component to a JLabel which contains an Icon. All you need to do is set a layout manager for the label. Something like:

    Java Code:
    JLabel background = new JLabel(....);
    background.setLayoutManager( new GridBagLayout() );
    Jlabel gamePiece = new JLabel(...);
    background.add( gamePiece );
    Now the game piece will be centered on the background.

  4. #4
    Join Date
    May 2011
    Location
    Maryland
    Posts
    38
    Rep Power
    0

    Default

    camickr, what kind of layout should i use? i still can't figure this out, the piece just appears next to the space rather than on top of it

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

Similar Threads

  1. Two Overlapping Components
    By javadeveloper2011 in forum AWT / Swing
    Replies: 4
    Last Post: 03-26-2011, 06:46 PM
  2. frame overlapping
    By sameerk in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-19-2010, 07:45 AM
  3. Overlapping JLabels
    By techbossmb in forum AWT / Swing
    Replies: 3
    Last Post: 09-21-2009, 03:21 PM
  4. Help with overlapping JPanels
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 03-09-2009, 10:19 PM
  5. overlapping forms
    By keerthi_y19 in forum New To Java
    Replies: 4
    Last Post: 08-26-2008, 10:30 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
  •