JEditorPane - mouse click simulation doesn't work

Hi all,
I have a little problem with my JEditorPane. I want to implement the posibility to put signs on a document loaded in a jeditorpane and save them. One solution is to save the position of the scrollbar, but because the font size can be changed it will not be working. So I want to simulate a cmouse click on the first row of text from viewport to put there the caret and take after that his position. The problem is that the simulation for the mouse click donesn,t work. The event is simulated, but the caret position is not changing.
I tried also using Robot class, but this implementation give me a serie a mouse events and it moves the cursor to the requested position and it's not the behaviour that I want.
Here is my code:import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.text.BadLocationException;
public class Reader {
     JEditorPane jEditorPane;
     JScrollPane editorScrollPane;
     private JFrame frame;
     private JPanel readerPane;
     private JPanel commandsPane;
      * @param args
     public static void main(String[] args) {
          new Reader();
     public Reader() {
          frame = new JFrame();
          createReader();
          createCommands();
          addPanes();
          frame.setSize(1000, 850);
          // frame.setExtendedState(frame.MAXIMIZED_BOTH);
          frame.setVisible(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          loadHtml();
     private void addPanes() {
          GridBagLayout layout = new GridBagLayout();
          frame.setLayout(layout);
          GridBagConstraints c = new GridBagConstraints();
          c.fill = GridBagConstraints.BOTH;
          c.gridx = 1;
          c.gridy = 0;
          c.ipadx = 0;
          c.ipady = 0;
          c.weightx = 1;
          c.weighty = 2;
          frame.add(readerPane, c);
          c = new GridBagConstraints();
          c.fill = GridBagConstraints.HORIZONTAL;
          c.gridx = 1;
          c.gridy = 1;
          c.ipadx = 0;
          c.ipady = 10;
          c.weightx = 0;
          c.weighty = 0;
          c.gridwidth = 1;
          c.gridheight = 1;
          frame.add(commandsPane, c);
     private void createCommands() {
          commandsPane = new JPanel();
          commandsPane.setBackground(Color.white);
          JButton backButton = new JButton("PUSH");
          commandsPane.add(backButton);
          backButton.addMouseListener(new MouseListener() {
               @Override
               public void mouseClicked(MouseEvent e) {
                    // TODO Auto-generated method stub
               @Override
               public void mouseEntered(MouseEvent e) {
                    // TODO Auto-generated method stub
               @Override
               public void mouseExited(MouseEvent e) {
                    // TODO Auto-generated method stub
               @Override
               public void mousePressed(MouseEvent e) {
                    MouseEvent click = new MouseEvent(jEditorPane,
                              MouseEvent.MOUSE_CLICKED, System.currentTimeMillis(),
                              16, 10, 200, 1, false, 1);
                    MouseListener[] listeners = jEditorPane.getMouseListeners();
                    for (int i = 0; i < listeners.length; i++) {
                         listeners.mouseClicked(click);
               @Override
               public void mouseReleased(MouseEvent e) {
                    // TODO Auto-generated method stub
     private void createReader() {
          jEditorPane = new JEditorPane();
          jEditorPane.setEditable(false);
          jEditorPane.setSelectionColor(Color.green);
          jEditorPane.addMouseListener(new MouseListener(){
               @Override
               public void mouseClicked(MouseEvent e) {
                    System.out.println("clicked");
                    System.out.println("caret pos = "
                              + jEditorPane.getCaretPosition());
               @Override
               public void mouseEntered(MouseEvent e) {
                    // TODO Auto-generated method stub
               @Override
               public void mouseExited(MouseEvent e) {
                    // TODO Auto-generated method stub
               @Override
               public void mousePressed(MouseEvent e) {
                    // TODO Auto-generated method stub
               @Override
               public void mouseReleased(MouseEvent e) {
                    // TODO Auto-generated method stub
          editorScrollPane = new JScrollPane(jEditorPane);
          editorScrollPane.setBorder(null);
          editorScrollPane.getVerticalScrollBar().setPreferredSize(
                    new Dimension(0, 0));
          readerPane = new JPanel();
          readerPane.setBackground(Color.black);
          readerPane.setLayout(new GridBagLayout());
          JPanel spacePane = new JPanel();
          spacePane.setBackground(Color.white);
          GridBagConstraints c = new GridBagConstraints();
          c = new GridBagConstraints();
          c.fill = GridBagConstraints.NONE;
          c.ipadx = 500;
          c.ipady = 650;
          c.weighty = 1;
          c.weightx = 1;
          c.gridx = 1;
          c.gridy = 1;
          c.gridwidth = 1;
          c.gridheight = 1;
          readerPane.add(spacePane, c);
          spacePane.setLayout(new GridBagLayout());
          c = new GridBagConstraints();
          c.fill = GridBagConstraints.BOTH;
          c.weighty = 1;
          c.weightx = 1;
          c.gridx = 0;
          c.gridy = 0;
          c.gridwidth = 1;
          c.gridheight = 1;
          c.insets = new Insets(20, 20, 20, 20);
          spacePane.add(editorScrollPane, c);
     private void loadHtml() {
          System.out.println("load html file");
          jEditorPane.setContentType("text/html");
          jEditorPane.setText("<html><body>" +
                    "<p>some text here for testing some text here for testing some text here for testing some text here for testing " +
                    "some text here for testing some text here for testing some text here for testing some text here for testing " +
                    "some text here for testing some text here for testing some text here for testing some text here for testing " +
                    "some text here for testing some text here for testing some text here for testing some text here for testing " +
                    "some text here for testing some text here for testing some text here for testing some text here for testing </p>" +
                    "</body></html>");
          jEditorPane.revalidate();
If tou run this code you can observe that when the "PUSH" button is pressed the jeditorpane receives a mouseclick event, but the caret position is not changing.
Strange is that when you click with the mouse over the editor pane the caret position is changed and I don't understand what is wrong.
Can you help me please?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

You can use viewToModel() method to get caret position for x, y location. No need to click.
Regards,
Stas

Similar Messages

  • Mouse clicks, scrolling doesn't work in applications from start screen (let's call it "tile application")

    Hello!
    I need help.
    2 days ago the mouse worked fine. Yesterday I noticed that the mouse scroll does not work in the "Book Bazaar Reader". Now I found that the right mouse button and left mouse button does not work in some applications, but scrolling work in these applications.
    In mail application clicks work in some panels, scrolling doesn't work.
    In desktop mode, the mouse works perfectly.
    Please help!

    Hi
    Since at desktop mode everything fine, i suspected some application or 3rd party SW change your mouse setting
    Go to run, msconfig, run as administrator, within the System Configuration dialogue box find startup tab, find KHALMNPR (if you using logitec mouse) and uncheck it
    click ok and restart
    or try to do clean boot to eliminate 3rd party SW issue

  • When resuming from standby mouse-click/keyboard doesn't work.

    When resuming from standby about 80% of the time the mouse on my Macbook Pro (Early 2011) stops working. I think it is a software issue. It appears that the mouse will do a click or click and drag but will not let go when removing my fingers. The issue only happens within 5seconds of waking up. The issue is only fixed with a hard reboot. I can bring up the shutdown menu, but am unable to slect shut down as the mouse/keyboard won't give input. This issue was present in Lion and was gone for the first few months of Mavericks but appeared again this week.
    I can freely move around the mouse cursor and enter expose with three fingers but cannot select anything.
    Any help would be appreciated.
    Thanks.

    You can use viewToModel() method to get caret position for x, y location. No need to click.
    Regards,
    Stas

  • Pen pressure simulation doesn´t work anymore.

    Hi everybody, my pen pressure simulation doesn´t work anymore. I am a pc user and have cs6 extended 64bit an a wacom cintiq 21ux with the newest drivers. By clicking stroke path, the path have over all the same thickness. But it should be thin at the begining and the end. Can anybody help me, please?

    In the Stroke Path dialog you have Simulate Pressure checked and in the Brush panel under Shape Dynamics>Size Jitter>Control you have Pen Pressure selected?
    You don't need a pressure tablet for the above operation.

  • My iPod photo's click wheel doesn't work.

    My iPod photo's click wheel doesn't work? I can click it but cannot scroll with it...
    Any suggestions?

    That is a hardware issue.  Take the iPod Nano to an Apple store or an AASP.  Whichever is more convenient for you.  If you want to DIY - iPod Repair Tutorials

  • I get this message when I try to open my google shared docs this week: "A browser error has occurred. Please hold the Shift key and click the Refresh button to try again." - but that click/refresh doesn't work either. What's up?

    # Question
    I get this message when I try to open my google shared docs this week: "A browser error has occurred. Please hold the Shift key and click the Refresh button to try again." - but that click/refresh doesn't work either. What's up?

    The backend end is in serious pain....on many levels.
    Try this: Connection Problems Form

  • The mouse scroll wheel doesn't work with Xorg

    I recently installed Solaris 10 on my x86 box. One issue is that the mouse scroll wheel doesn't work with Xorg. Hmmm... Okay, it sometimes did work, and most of the time went on strike, and recovered at random. This pattern continued.
    My mouse is an ordinary PS/2 one with two buttons and a scroll wheel. I want to promise that there's absolutely nothing wrong with it per se. Here is some info:
    $ uname -a
    SunOS arbiter 5.10 Generic_127112-07 i86pc i386 i86pc
    $ grep -i mouse /var/log/Xorg.0.log
    (**) |-->Input Device "Mouse0"
    (II) LoadModule: "mouse"
    (II) Loading /usr/X11/lib/modules/input//mouse_drv.so
    (II) Module mouse: vendor="X.Org Foundation"
    (==) NVIDIA(0): Silken mouse disabled
    (II) Mouse0: Setting Device option to "/dev/mouse"
    (**) Mouse0: Protocol: VUID
    (**) Mouse0: Core Pointer
    (**) Option "Device" "/dev/mouse"
    (**) Mouse0: ZAxisMapping: buttons 4 and 5
    (**) Mouse0: Buttons: 9
    (II) XINPUT: Adding extended input device "Mouse0" (type: MOUSE)
    # The section about mouse in /etc/X11/xorg.conf follows:
    Section "InputDevice"
            Identifier  "Mouse0"
            Driver      "mouse"
            Option      "Protocol" "auto"
            Option      "Device" "/dev/mouse"
            Option      "Buttons" "5"
            Option      "ZAxisMapping" "4 5"
            Option      "Emulate3Buttons" "false"
    EndSection
    # Note that the only result of explicitly changing protocol to ExplorerPS/2, PS/2, IMPS/2 or whatever else is that the cursor jumped here and there and everywhere when I moved the mouse.I ever post one in comp.unix.solaris to ask for help but got no effective solution. Thank you all.

    You remember correctly, Yvan.
    The 6.2.9 updater is available http://www.apple.com/support/downloads/appleworks629formac.htmlhere. Note that the updater is language specific. The one at the top of the list is for the International English version of AppleWorks. The US English version is the one in the box at the upper right, identified only by its file size.
    Regards,
    Barry

  • ITunes 10.4.1.10 how to stop downloads of free news pods?  (right click delete doesn't work) also can't scroll down list of downloads!

    (ITunes 10.4.1.10) How to stop downloads of free news pods?  (right click delete doesn't work)
    Also can't scroll down list of downloads so as to pause them.  Would like to delete them as ISP has download limit.
    Thanks in advance!  (this seems to be a dumb problem of the software having a life of its own!)

    I have been talking to Apple support about this very problem. So far they have asked me to disable both Firewall and Anti Virus software (Windows Firewall and ESAT NOD32 anti virus) - this didn't work. Rebuild my library - this didn't work. Un-install all Apple applications and re-install - this didn't work. I have created a second user account on my PC and from that account (both accounts set as Administrator) I can activate Genius. This suggests to me that the problem is possibly linked to my original User Account, which is the one I always use. I am waiting for the next update from Apple and will post an update if/when the problem is resolved.
    What I also notice is about 2 seconds in to Step 2 of the Genius activation, the progress diagonal lines bar stops, and then starts again. As soon as I see this short freeze I know that the activation will fail.

  • In Yosemite, Magic Mouse double-click function doesn't work

    On my iMac running Yosemite 10.10.2, the double-click function on the Magic Mouse no longer works. So to open a folder, or anything for that matter, I must always do click-control ---and that doesn't work for everything. For example, I can't double click on a character in Glyphs, so this renders Glyphs useless. And so on... I have gone into preferences to see if anything was amiss in the settings, but everything checked out fine. Is there a fix for this, or do I have to wait for the next upgrade for Yosemite? Help! Thanks... --Royce

    What's the answer to this mouse problem, please? Why does my double-click no longer work on my magic mouse since downloading Yosemite 10.10.2 to my iMac? 
    What's up Apple?
    Mark

  • Xcelsius/Dashboard Design - mouse over capability doesn't work/losing hover

    Hello there,  I am currently in a tough situation.  If any Xcelsius gurus can provide me with a solution, I would very much appreciate your help.
    I currently have a dashboard with pie chart component in the default view.  It has a radio button with two values.  The mouse over doesn't work when the dashboard is loaded.  However, when I make a selection in the radio button, the mouse over works for both the options.  I have noticed this is a bug but if anyone has a solution or way around it, let me know.
    Another issue - I have a 'All' view and 'Region' views in the menu bar.  When a user clicks on a particular Region, then clicks all and goes back to a region, I lose the drill down capability on the pie chart thats on the Region view.  initially, the mouse over and drill down works fine.  However, after going to the All view and coming back to a region, this capability is lost.  It acts the same way as the problem above.  User can't hover nor drill down.  If anyone has a solution to this, let me know.

    FYI this is the article on the main forum page:
    Announcement: New to Spry, or  the Spry forums?
    Hide Details
    Before you post a topic please verify that:
    You are using the latest Spry files
    The latest version of the Adobe Spry Framework is 1.6.1, this is the same version that ships with Dreamweaver CS4. If you use Dreamweaver CS3 (uses Spry 1.4), its wise to upgrade your files to the latest version. This can easily be done using the Spry Updater that can be found here.
    After that we will have a look at your code.
    Ben

  • Booting problem, mouse and keyboard doesn't work for 2 minutes

    I got a brand new mac mini 2.4Ghz just 3 weeks ago, got a few problems over the last week that I've been able to fix, but now I'm stuck with a problem when booting. The booting process seems a bit slow, and once the desktop has been fully loaded, the keyboard and mouse doesn't work, and the computer is using the non-calibrated Display Profile. After about 2 minutes, the display profile change to calibrated, and the mouse and keyboard work again. I have no clue about how to fix that problem, and I'm thinking about bringing the computer to an Apple Store by tomorrow if I can't fix it.

    Welcome to  Discussions!
    Check your login items to see what's there. You may have too much going on at login which is causing the serious delay in loading time.
    To check the login items, open System Preferences, under the System section click Accounts, click your account name, then click the tab at top labeled Login Items. If you want to remove an item in the list, click the item then click the - button below the list.

  • My i pod nano click wheel doesn't work. how do i fix it?

    my i pod nano click wheel has stopped working. My i pod still works when in my docking station but the wheel doesn't. Anyone got any ideas what I can do? I've tried to restore settings but that hasn't worked.

    That is a hardware issue.  Take the iPod Nano to an Apple store or an AASP.  Whichever is more convenient for you.  If you want to DIY - iPod Repair Tutorials

  • Mouse scroll-down doesn't work....

    LIttle trackball for scrolling on my mouse doesn't work when attempting to scroll down. I've looked at the pref settings for it, and it all seems fine. It will move in all other directions, just not down.
    Advice please?

    Glad it worked. Folks seem to have varying probs w the scroll wheel. I have been lucky. 1st one lasted 4 months and would not clean. Free replacement. This one is now going on a year w a couple of minor cleans.
    *Thanks for the Green Star.* Joyous Computing, JP

  • Bing Maps on IE 11 browser, The mouse click event is only working when we have compatibility mode on.

    I have tried out the code in this article in ASP.Net web forms with c#  and javascript.
    I am using Ajax to call the C# from Javascript and load the data from database.
    I have used following article to show the pushpins and there infoboxes.
    http://blogs.msdn.com/b/rbrundritt/archive/2013/11/08/multiple-pushpins-and-infoboxes-in-bing-maps-v7.aspx?CommentPosted=true#commentmessage
    My code works great on IE 11 , when I have compatibility mode on,
    but when compatibility mode is off, the mouse click event is not being received by the Javascript function.
    Is this expected behavior of bing maps, Are there any workarounds for this problem?
    Thanks
    Nate

    Hi Ricky, I have tried using Chrome and I see the same issue. The mouse events are not being captured. 
    Here is my code
    <%@ Page Title="" Language="C#" MasterPageFile="~/Maps.Master" AutoEventWireup="true" CodeBehind="BingMaps.aspx.cs" Inherits="MyMaps.secure.BingMaps" %>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderBody" runat="server" >
    <asp:ScriptManager ID="ScriptManager" runat="server"
    EnablePageMethods="true" />
    <div id="MapHolder" style="; width:1000px; height:800px; " />
    <asp:Literal ID="Literal1" runat="server">
    </asp:Literal>
    </asp:Content>
    <asp:Content ID="Content3" ContentPlaceHolderID="ScriptSection" runat="server">
    <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0">
    </script>
    <script type="text/javascript" >
    var map = null, infobox, dataLayer;
    $(document).ready(function () {
    GetMap();
    function GetMap() {
    // Initialize the map
    map = new Microsoft.Maps.Map(document.getElementById("MapHolder"),
    { credentials: "lincensekey", zoom: 2 });
    dataLayer = new Microsoft.Maps.EntityCollection();
    map.entities.push(dataLayer);
    var infoboxLayer = new Microsoft.Maps.EntityCollection();
    map.entities.push(infoboxLayer);
    infobox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0, 0), { visible: false, offset: new Microsoft.Maps.Point(0, 20) });
    infoboxLayer.push(infobox);
    PageMethods.GetLocations(RequestCompletedCallback, RequestFailedCallback);
    function AddData(MapPoints) {
    for (var i = 0, len = MapPoints.length; i < len; ++i)
    var pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(parseFloat(MapPoints[i].lat),parseFloat(MapPoints[i].lon))
    icon: MapPoints[i].group,
    height: 50, width: 60, text: MapPoints[i].city
    pushpin.Title = MapPoints[i].name;
    pushpin.description = MapPoints[i].desc;
    Microsoft.Maps.Events.addHandler(pushpin, 'click', displayInfobox);
    dataLayer.push(pushpin);
    function displayInfobox(e) {
    if (e.targetType == 'pushpin') {
    infobox.setLocation(e.target.getLocation());
    infobox.setOptions({ visible: true, title: e.target.Title, description: e.target.description });
    function RequestCompletedCallback(result) {
    result = eval(result);
    AddData(result);
    function RequestFailedCallback(error) {
    var stackTrace = error.get_stackTrace();
    var message = error.get_message();
    var statusCode = error.get_statusCode();
    var exceptionType = error.get_exceptionType();
    var timedout = error.get_timedOut();
    alert("Stack Trace: " + stackTrace + "<br/>" +
    "Service Error: " + message + "<br/>" +
    "Status Code: " + statusCode + "<br/>" +
    "Exception Type: " + exceptionType + "<br/>" +
    "Timedout: " + timedout);

  • When-mouse-click trigger is not working

    Hi,
    My forms version is 10g.
    I've a black level and item level when-mouse-click trigger.
    There is some code inside that which is not being executed.
    To test, i simply printed a hello message inside the trigger's code.
    Even hello is not being displayed.
    Can anyone please help me in why this trigger is not working.
    Navnit

    You have some other issues going on if you don't see anything from a when-mouse-click trigger.
    First of all, are you spelling the trigger using a dash or underscore? WHEN-MOUSE-CLICK will run, but WHEN_MOUSE_CLICK will not.
    Have you set :SYSTEM.Message_Level to some value above zero in the form? If so, set it back to zero.
    On what object are you trying to click? Is this causing navigation? Navigation may cause validation to run, which may fail, which may prevent the navigation, which may prevent your when-mouse-click from running.
    And last, are you sure you are running the currently compiled fmx version of your form?
    When nothing works, you need to back up and start finding out what DOES work first.

Maybe you are looking for

  • Fed up with Adobe's customer service

    I have to say that Adobe takes the cake as the most inept company in the US, along with AT&T. I filed my application for the free upgrade from CS5.5 in early May, right away they asked me for the invoice, even though I had sent them PDFs of the order

  • How do I integrate SpeedGrade into my Photoshop workflow?

    This will likely sound insane, since SpeedGrade is obviously geared toward video projects, and Photoshop toward processing of still photos, but please hear me out. I love Photosop CS6, and my absolute favorite new feature is the Color Lookup adjustme

  • Problems with Embedded classes mapping

    Hi, I'm experiencing problems for table generation with the following case: a class declares two fields; one of them typed as a subclass of the other; both fields annotated with @Embedded; the subclass uses the annotation @AttributeOverride to avoid

  • BUG: Oracle Schema Processor does not work in Servlets

    We found a bug with Oracle's Schema Processor. It does not work in Servlets. When we try to validate a XML document in a Servlet it does not work, but we can execute the same code in a stand alone application and it works. The following is the code w

  • Bex to Business Objects - Currency Conversion error in Webi

    Hello, I am attempting to transfer a Bex 7 key figure currency conversion to a Business Objects filter in a Universe for display in a Webi report.  The version of Business Objects XI 3.1 SP2.  The Bex Conversion Type is based off Calendar Month, and