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

  • Home
  • SEARCH
  • 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 6076159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:34:33+00:00 2026-05-23T10:34:33+00:00

I am using jLayeredPane in my Java GUI. I added some panels(jPanelsLayer1) on DEFAULT_LAYER

  • 0

I am using jLayeredPane in my Java GUI. I added some panels(jPanelsLayer1) on DEFAULT_LAYER of my jLayeredPane and also each jPanel has a MouseAdapter that Overrides mouseEntered and mouseExited for my purposes. When I add another components(jPanelsLayer2) on the PALETTE_LAYER of JlayerdePane, on the top of jPanelsLayer1, and defined MouseAdapter for them, I have problem. When mouse entered the common area mouseEntered and mouseExited of jPanels of different layers run consecutive several times. I want only jPanelslayer2 mouseAdapters to be active when they are seen on the top of jpanelLayer1. Maybe a solution be to remove jPanelLayer1 mouseAdapter. But this is not effective.

Please guid me…..sajad

  • 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-05-23T10:34:34+00:00Added an answer on May 23, 2026 at 10:34 am

    I’m not sure where your problem is because when I test it, the mouse is only active in the Palette panel when it is above the Palette panel even if the the Palette panel is over the Default panel. For instance here is my SSCCE to test the concept. Feel free to modify this to show us your problem:

    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Point;
    import java.awt.event.*;
    
    import javax.swing.*;
    
    @SuppressWarnings("serial")
    public class LayeredFun extends JLayeredPane {
       private static final int JLP_WIDTH = 400;
       private static final int JLP_HEIGHT = 400;
       private static final Dimension PANEL_SIZE = new Dimension(200, 200);
    
       public LayeredFun() {
          JPanel defaultPanel = createPanel("Default Panel", new Point(10, 10), Color.cyan);
          JPanel palettePanel = createPanel("Palette Panel", new Point(100, 100), Color.pink);
    
          add(defaultPanel, JLayeredPane.DEFAULT_LAYER);
          add(palettePanel, JLayeredPane.PALETTE_LAYER);
       }
    
       private JPanel createPanel(String name, Point location, Color color) {
          JPanel defaultPanel = new JPanel();
          defaultPanel.setSize(PANEL_SIZE);
          defaultPanel.setLocation(location);
          MyMouseAdapter defaultMouseAdapater = new MyMouseAdapter(name);
          defaultPanel.addMouseListener(defaultMouseAdapater);
          defaultPanel.addMouseMotionListener(defaultMouseAdapater);
          defaultPanel.setBackground(color);
          defaultPanel.setBorder(BorderFactory.createTitledBorder(name));
          return defaultPanel;
       }
    
       @Override
       public Dimension getPreferredSize() {
          return new Dimension(JLP_WIDTH, JLP_HEIGHT);
       }
    
       private class MyMouseAdapter extends MouseAdapter {
          private String name;
    
          public MyMouseAdapter(String name) {
             this.name = name;
          }
    
          @Override
          public void mouseEntered(MouseEvent e) {
             System.out.printf("%s: mouseEntered%n", name);
          }
    
          @Override
          public void mouseExited(MouseEvent e) {
             System.out.printf("%s: mouseExited%n", name);
          }
    
          @Override
          public void mouseMoved(MouseEvent e) {
             System.out.printf("%s: mouseMoved%n", name);
          }
       }
    
       private static void createAndShowUI() {
          JFrame frame = new JFrame("LayeredFun");
          frame.getContentPane().add(new LayeredFun());
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using C#, I need a class called User that has a username, password, active
I am using netbeans IDE to develop a GUI for a java program. I
I'm using a custom JLayeredPane. I have several Shapes which needed to be drawn
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I am trying to add a JLayeredPane to a JPanel and then add an
Using C++ preprocessor directives, is it possible to test if a preprocessor symbol has
I am using PersonaC30 card printer to print my Jpanel data on card. My
Using Qt Creator, I have set a QWidget's background property to black. However, some

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.