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 3344860
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:07:06+00:00 2026-05-18T01:07:06+00:00

I seem to be having a problem with JTextPane. I have extended JTextPane to

  • 0

I seem to be having a problem with JTextPane. I have extended JTextPane to render a floating image because the JTextPane icon functionality does not suit my purpose. I want the user to be able to click on the image, and have certain events performed. However, when I click on the image, even when I use evt.consume(), the caret and selection are updated in the JTextPane. I would like clicks and mouse events in general that interact with the image to not affect the caret position or selection at all. Relevant code:

public class JTextPaneImg extends JTextPane {

    public JTextPaneImg(){
        super();
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                formMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                formMouseReleased(evt);
            }
        });
    }

    private void formMousePressed(java.awt.event.MouseEvent evt) {                                  
        if (imgBound.contains(evt.getPoint())) {
             evt.consume();
             //Do some stuff in here to interact with the image
             // but the event still undesirably interacts with selection/caret
        }
    }   


    private void formMouseReleased(java.awt.event.MouseEvent evt) {                                  
        if (imgBound.contains(evt.getPoint())) {
             evt.consume();
             //Do some stuff in here to interact with the image
             // but the event still undesirably interacts with selection/caret
        }
    }   
}

I have even called getMouseListeners and verified that my own mouse listener is the last in the array, I read that listeners are called from highest to lowest index, meaning if my listener calls consume, it should be the last to act on the event. Why is my mouse click event still updating the caret then? Is this a problem with the Look and Feel?

  • 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-18T01:07:06+00:00Added an answer on May 18, 2026 at 1:07 am

    I read that listeners are called from highest to lowest index, meaning if my listener calls consume, it should be the last to act on the event

    This order is not guaranteed. All that is guaranteed is that all listeners will be notified. I believe it is up to each listener to check if the event is consumed. At least that is my understanding

    You might be able to use a Global Event Dispatcher to prevent the event from being dispatched to the component. Just remember that all events go through the dispatcher so the code should be efficient so you don’t slow down the queue.

    Or you can use the technique presented on Mouse Wheel Controller which removes all the listeners from the components and replaces it with your custom listener. You can then decide when to forward the events to the other listener.

    Or maybe your image should be painted on the viewport, not the text pane.

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

Sidebar

Related Questions

I seem to be having a problem removing the image in UIScrollView. I was
I seem to be having a problem with a macro that I have defined
I seem to be having a problem withs tring encoding. I have the following
I seem to be having an interesting problem only in chrome (not IE, FF).
I seem to be having a problem where I have an a4j:commandLink on a
Hello I seem to be having some problem involving counting in Django. I have
I seem to be having a problem checking if a string exists in my
I seem to be having a problem with checking for list equality. In my
I seem to be having a problem with my footer growing to 100% width
Hi all I seem to be having a problem with my jQuery mobile script.

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.