Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8539999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:29:58+00:00 2026-06-11T11:29:58+00:00

I want to overlap two image. For that, I use JLabel and set an

  • 0

I want to overlap two image. For that, I use JLabel and set an ImageIcon to it. I also have a JPanel using a gridlayout containing my images (like a tile-based map). So far, no problem and it works great.

The problem I encounter, is when I tried to overlap two image. For that, I tried with a JLayeredPane in the gridlayout and put two images (JLabel) in a different level. This method throws me this exception:

Exception in thread “AWT-EventQueue-0” java.lang.IllegalArgumentException: Comparison method violates its general contract!

I made some research and tried to downgrade to jdk-6 instead of 7, cause it appears that in the jdk-7 it doesn’t work well. The exception has now disappeared, but nothing is drawn on the screen.

Then I tried a new method by creating a class that extends JComponent and I override the paintComponent() method. My class contain an arrayList of my images (JLabel) and in the paintComponent method, I iterate through the arrayList and call each label’s paintComponent method with the Graphics object of my own class. The same exception is raised.

Here’s a sample my paintComponent method:

@Override
public void paintComponent(Graphics g) {
    for(JLabel label : this.images) {
        label.paintComponents(g);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:30:00+00:00Added an answer on June 11, 2026 at 11:30 am

    you can to use

    1. JLayer (Java7) based on JXLayer (Java6)

    2. GlassPane

    3. OverlayLayout

    4. JLayeredPane

    then you can (for example) moving or animate with Icons / ImageIcons placed in JLabel

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two UILabels. that I want to overlap one atop the other. Call
If I have two ranges that overlap: x = 1..10 y = 5..15 When
I have two image views. They are puzzle pieces I want to test if
Is there any function to recognize that two controls have overlap in xcode? i
I have two overlay images that I want show in camera view depending on
I have two images they actually do not overlap but I also can't have
Ho I have two list view on a frame layout. I want one overlay
I have a tiling background image, but I want to overlay another tiling image
Ok so I have a Background background-image: url('images/body.png'); now I want to overlay a
I want to create an overlay that I will use behind a popup. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.