Rectangle 27 2

You can get source from here http://java-sl.com/JEditorPaneStructureTool.html It shows how to obtain text view bounds. First you get caret position for current mouse poiunter using viewToModel() method. Then go down the Views tree achieving leaf view and calcualte it's bounds. See this http://java-sl.com/tip_view_rectangle.html

If your mouse pointer in the view's rectangle then your mouse over text.

You can check whether the text in caret position is link and show your tooltip.

java - Formatting JEditorPane's cursor, tooltips, links - Stack Overfl...

java html swing hyperlink jeditorpane
Rectangle 27 10

Not entirely sure I understand what's going wrong (just let me know if I'm off, so I can delete this :-)

Assuming you want to get the "real" component under the mouse (click/press) which triggered the start of editing, the trick is to do the conversion (from parent to editor coordinates) after the editor is added to its parent. That's guaranteed for shouldSelectCell, but not for isCellEditable (the latter being called before)

A recent answer in the context of a tree (should be similar enough) has some runnable example. Here's the relevant snippet:

/**
 * At this point in time the editing component is added to the table (not documented!) but
 * table's internal cleanup might not yet be ready
 */ 
@Override
public boolean shouldSelectCell(EventObject anEvent) {
    if (anEvent instanceof MouseEvent) {
        redirect((MouseEvent) anEvent);
    }
    return false;
}

private void redirect(final MouseEvent anEvent) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            MouseEvent ev = SwingUtilities.convertMouseEvent(anEvent.getComponent(), anEvent, editor);
            // at this point you have the mouse coordinates in the editor's system
            // do stuff, like f.i. findComponent
            ....
        }
    });
}

+1 In retrospect, one can see that p3 was showing the previous position.

@trashgod - good observation, missed that :-)

java - How can I get the component at the mouse click position, when u...

java swing jtable mouselistener tablecelleditor
Rectangle 27 1

This is not an answer to your question but an explanation of the result you see: findComponentAt() returns null because "there is no child component at the requested point." MyCellPanel is located on a CellRendererPane used by JTable to speed rendering. There's an example of how it's used here.

java - How can I get the component at the mouse click position, when u...

java swing jtable mouselistener tablecelleditor
Rectangle 27 1

You can get the table's row and column from the clicked point. Then call the same renderer's getTableCellRendererComponent method to get renderer component. Then correct point subtracting previous rows' heights from y and previous cells' widths from x. Then get proper child of rendered component.

But how do I get "proper child of rendered component"? I can't get it with findComponentAt() in this case either.

You can write own findComponentAt. Get all children and for each of them get bounds and check whether event x/y (corrected ones) are in the bounds.

java - How can I get the component at the mouse click position, when u...

java swing jtable mouselistener tablecelleditor
Rectangle 27 0

You can get the table's row and column from the clicked point. Then call the same renderer's getTableCellRendererComponent method to get renderer component. Then correct point subtracting previous rows' heights from y and previous cells' widths from x. Then get proper child of rendered component.

But how do I get "proper child of rendered component"? I can't get it with findComponentAt() in this case either.

You can write own findComponentAt. Get all children and for each of them get bounds and check whether event x/y (corrected ones) are in the bounds.

java - How can I get the component at the mouse click position, when u...

java swing jtable mouselistener tablecelleditor
Rectangle 27 0

You don't need to use OpenGL specific libraries to do this, it can easily be accomplished with the Robot class, which contains a mouseMove() method - it does what it says on the tin.

As far as I'm aware both Robot and GLUTWarpPointer generate low level system events to move the mouse, thus achieving the same thing. I assume you're using JOGL which as far as I know doesn't expose the mouse moving functionality of GLUTWarpPointer, so if that's correct Robot is probably the only sensible option.

But that doesn't move it relative to the window, also, I need to know how to get the relative position of the mouse, btw, Component.getLocationOnScreen().x -How do I get the component if it's a window made in OpenGL

mouse - Set and get cursor position? JAVA w/ OpenGL - Stack Overflow

java mouse
Rectangle 27 0

Here is simple example with help of viewToModel() and getLineOfOffset() methods:

import java.awt.BorderLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.text.BadLocationException;

public class TestFrame extends JFrame {

    private JTextArea area;
    private JLabel l;


    public TestFrame() {
        init();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pack();
        setLocationRelativeTo(null);
        setVisible(true);
    }


    private void init() {
        area = new JTextArea(5,5);
        area.addMouseMotionListener(getListener());
        l = new JLabel(" ");

        add(new JScrollPane(area));
        add(l,BorderLayout.SOUTH);
    }

    private MouseMotionListener getListener() {
        return new MouseMotionListener() {

            @Override
            public void mouseMoved(MouseEvent e) {

                int viewToModel = area.viewToModel(e.getPoint());
                if(viewToModel != -1){
                    try {
                        l.setText("line: "+(1+area.getLineOfOffset(viewToModel)));
                    } catch (BadLocationException e1) {
                        e1.printStackTrace();
                    }
                }
            }

            @Override
            public void mouseDragged(MouseEvent e) {
            }
        };
    }


    public static void main(String args[]) {
        new TestFrame();
    }

}

java - JTextArea - get the line of the current mouse position - Stack ...

java swing jtextarea
Rectangle 27 0

The problem has been fixed in the JDK8 Early Access Release. You can either download that version, or wait until it comes out. It was fixed in February as part of this ticket: RT-28129

I entered a ticket on the JavaFX Jira. You can follow it to see the status updates.

I've updated the demo to reflect your problem. It seemed to work when the transformation was using the z-axis (yesterday - different for me today), but not when the transformation was on the X or Y axes.

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Point3D;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.RotateBuilder;
import javafx.stage.Stage;


public class JFXRotationXOrds  extends Application{

    @Override
    public void start(Stage primaryStage) throws Exception {
        VBox root = new VBox();
        final Rotate rotate = RotateBuilder.create().angle(80).pivotX(100).pivotY(100).pivotZ(0).axis(new Point3D(1,0,0)).build();
        root.getTransforms().add(rotate);
        root.setStyle("-fx-border-color: black; -fx-border-width:5; ");

        root.setOnMouseMoved(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent arg0) {
                if(arg0.getEventType() == MouseEvent.MOUSE_MOVED){
                    System.out.println(arg0.getSceneX() + "," + arg0.getSceneY());
                }
            }
        });

        Scene scene = new Scene(root, 200, 500);
        PerspectiveCamera camera = new PerspectiveCamera();
        scene.setCamera(camera);
        primaryStage.setTitle("BorderPane Example");
        primaryStage.setScene(scene);
        primaryStage.show();

    }

    public static void main(String[] args){
        Application.launch(args);
    }
}

In 2D it works fine but in 3D it doesn't, try to add a 3D rotate to your root and set perspective camera for your scene.

Ah - You did state rotating on the X axis, but your screenshot seemed to indicate rotation around the Z axis. I can see the problem now... I'm thinking you might be able to do some calculation using the formulas here (but haven't done the math to prove it): docs.oracle.com/javafx/2/api/javafx/scene/transform/Affine.html

@Eeliya - The problem seems to be fixed in the JDK8 Early Access Release. See answer's update for more details.

java - Get mouse position on node relative to it's coordinates and tra...

java javafx javafx-2
Rectangle 27 0

There should be a hit test function call in your if statement. The hit test function should translate from mouse coordinates to Cell coordinates for the current (i,j) position, and return a simple true or false. (And as soon as you get a true, you can exit both loops.)

You don't show how you are drawing the grid, though. If your grid starts at a position (xp,yp) and every cell has a height h and width w, you can easily convert mouse coordinates directly into cell coordinates:

cellx = (mousex - xp)/w
celly = (mousey - yp)/h

... where a cellx,celly < 0 or >= size would indicate a click outside the grid.

java - how to get element position in 2D array when mouse clicked? - S...

java arrays swing position mouselistener
Rectangle 27 0

As pointed out by @Hunter-mcmillen: you are confused about java operators.

public  void  mouseMoved(MouseEvent e) { 

        double distance1 = Math.pow((e.getX() - x1),2);
        double distance2 = Math.pow((e.getY() - y1),2); // Math.pow(a,b) == a^b (in a calculator)

        setdistance(Math.sqrt(distance1 + distance2));
        System.out.println(getdistance()); 
}

I really recommend that you read more carefully the Java operators before assuming how they work on the language.

I recommend also that you create a JPanel or JLabel for this picture, and then load such picture inside this new Jpanel or Label or other component.

public class Paint extends JPanel implements ActionListener {
    Mouse swim = new Mouse();
    Timer tm = new Timer(7, this);
    public void paintComponent(Graphics g) {
    // Try this:
    ImageIcon swimminghold = new ImageIcon(render.class.getResource("resources/Swimmingpoolns.png")); 
    swimmingpool = swimminghold.getImage();
    JLabel label = new JLabel();
    label.setIcon(swimminghold);
    label.addMouseMotionListener(swim);
    addMouseMotionListener(swim);
    label.addMouseMotionListener(swim);
    addMouseMotionListener(swim);

        //Do something

        /* ...*/
}

Ive updated the code however in "public void paintComponent(Graphics g) {" swim.getdistance() is still printing 0

the problem is that getdistance() is always returning 0 in "public void paintComponent(Graphics g).

Ive updated the code to show the loading of images , however moving away from that , any variables that are changed outside of public void paintComponent(Graphics g) will not update in public void paintComponent(Graphics g) no matter what i try;

in my case , in the Mouse class , i store a variable called distance I created a getter for this variable. Whenever I call this getter in public void paintComponent(Graphics g) it will always show 0 , not updating. This getter works anywhere else apart from public void paintComponent(Graphics g).

swing - Cannot get mouse position in Java - Stack Overflow

java swing mouseevent
Rectangle 27 0

Without knowing much about what is on the screen we can apply the following. As long as there is no offset from the edge of the canvas to where you rendered the cells you can use the follow, if there is offset, you will need to add it to the x,y coordinates.

int x = 201;  //You would use e.getX();
int y = 10;   //You would use e.getY();

int xWidth = 50;
int yWidth = 50;

//Divide by the width to get the array position
int xIndex = (int)Math.floor(x / xWidth);
int yIndex = (int)Math.floor(y / yWidth);

java - how to get element position in 2D array when mouse clicked? - S...

java arrays swing position mouselistener
Rectangle 27 0

Input input = gc.getInput();
int xpos = input.getMouseX();
int ypos = input.getMouseY();

Java - Slick2D/lwjgl get mouse position - Stack Overflow

java position mouse lwjgl slick2d
Rectangle 27 0

I have figured it out. I used the lwjgl.jar from the lwjgl-2.9.2 download folder and it worked. I guessed using the one that came with Slick2D was buggy or something. Maybe my set up was wrong from the start? Anyways, I got it to work.

Java - Slick2D/lwjgl get mouse position - Stack Overflow

java position mouse lwjgl slick2d
Rectangle 27 0

i do not want to get tho position of the mouse , its is a board game and i want to get the position of square , the user clicked on it .

@Michael Samir again to re_read comment by Andrew Thompson about SSCCE, edit your question with code in this form, then after you can want to something, otherwise this question (and with contraproductive comments) isn't answerable ...

java - in the mouse click method when i call the method get X() and ge...

java awt mouseevent mouselistener mouse-listeners
Rectangle 27 0

I decided to just make a translucent window the size of the screen (which is barely visible) and collected the mouse positions that way. It seemed to work, but I was hoping that I wouldn't have to paint an extra component.

  • User is able to see through the window and can click where one wants

java - How do I get the mouse position on click when it is outside of ...

java click mouse mouse-position
Rectangle 27 0

Ok Guys i found the solution now:

MouseInfo.getPointerInfo().getLocation().x - XYZ.getLocationOnScreen().x
 MouseInfo.getPointerInfo().getLocation().y - XYZ.getLocationOnScreen().y

with XYZ being the reference to the Frame / Panel / whatever being used

position - (Java) Get Mouse Coordinates Within Window - Stack Overflow

java position mouse
Rectangle 27 0

In SWT you need not be in a listener to get at the mouse location. The Display object has the method getCursorLocation().

Display.getCurrent().getCursorLocation()
PlatformUI.getWorkbench().getDisplay().getCursorLocation()

For SWT applications, it is preferable to use getCursorLocation() over the MouseInfo.getPointerInfo() that others have mentioned, as the latter is implemented in the AWT toolkit that SWT was designed to replace.

java - Get Mouse Position - Stack Overflow

java mouse
Rectangle 27 0

Try looking at the java.awt.Robot class. It allows you to move the mouse programatically.

java - Get Mouse Position - Stack Overflow

java mouse