How would I let a user draw lines on a canvas in JavaFX? I define a line as where the mouse went over between a click and a release. I'm thinking of using a mouse event handler and a Path, but I was wondering if there's anything built in that I could use. Thanks!
I have a small program that allows the user to draw lines from a tree on the left to a tree on tree on the right.
If the user clicks on an item in the left tree, a line is drawn and the endpoint is bound to the mouse position (a custom handler is registered to monitor for mouse movement and updates two properties that allow you to bind to it). This works great.
Related
I want to generate mouse click events for a Java application. I am aware that there is java.awt.Robot, which would allow me to do this. However, I would like that the generated mouse events do not actually affect the "cursor". That is, I would like to be able to minimize the window of the Java program and do other things with the mouse cursor, while mouse events are still generated for that program. How could I do that?
Edit: Furthermore, I cannot be assumed that there is a number of buttons that I need to interact with. Rather I'd like to generate mouse click events as if I had clicked at a certain position within the window.
I am looking at marking an image with circle an cross and the program would be counting the cross and circle.
Example : right Click -> cross and left click ->circle
I also wish to be able to click again on the circle or the cross to make it disappear.
So what I wish is to not use a button. Example of what I want to achieve: i have a photo with a lot of cats and dogs: I want the number of animal in the image so if I click right on the image on a cat I will see a cross appear and if I click left on a dog I will see a circle. visually I can see if I clicked on each animal and the program can count the number of click right and click left to tell me how many dog and how many cats I have in the picture.
Do any of you could help me to put me in the right direction to do that? If it is possible.
What you can do, is check if the button has been enabled or not. If it has been clicked, then you can set the image that was added onto the picture, to the original picture.
Yes, it's possible.
First, create a GUI model class to hold the image and a List of markers. Create a Marker class to hold a boolean and a java.awt.Point. The boolean determines whether to draw a cross or a naught. The Point determines where to draw the cross or naught.
You'll have to determine how close to an existing marker Point counts as a deletion, rather than an addition.
Second, create a JFrame and a drawing JPanel to hold the image. You can look at the Oracle tutorial Performing Custom Painting to see how to create a drawing JPanel.
Third, create a control JPanel to display the number of crosses and naughts in the GUI model List.
Fourth, create a MouseAdapter to listen for mouse clicks, and add or remove a marker for the GUI model List, depending on whether the marker exists or not.
Here's what the GUI might look like.
I need your help with my application.
I'm writing a program that displays big images in tiles, using the SWT MapWidget (http://mappanel.sourceforge.net/swt/).
The user has the ability to place markers on the map, when he pressed the mouse for a couple seconds. Additionally, I also need a little ZoomBox next to the cursor that shows the area around the cursor, so that the user has better precision when placing a marker. This ZoomBox is to be displayed while the user keeps the mouse pressed. Placing the markers ia already working fine.
I have problems with implementing the ZoomBox, specifically displaying it. I found a post that does just what I need (Zoom box for area around mouse location on screen). The problem is, this post is for Swing and not for SWT.
I have already built a SWT_AWT-Bridge, so I have the ZoomPanel already in my shell. What I need is the functionality of displaying it on top of the MapWidget, while the user keeps the mouse pressed.
I figured, I need to use a StackLayout, but I don't know how.
EDIT
To clarify, my question is, how can I display the composite containing my ZoomBox on top of my image, while the user keeps the mouse pressed?
i'm looking for this effect, but PulpCore doen't works with swing. Do you know what library use, or how to make a TileMap? Also, I'd like to move forever in it.
Thanks.
I'm guessing you don't want to use an actual world-map implementation like JXMapViewer...
The basic functionality appears to be: click on some coordinates, and that point becomes centered in the viewport. One fairly simple way to do this is to have the component(s) that you want to view all contained within a JPanel and have that panel inside a JScrollPane with its scrollbars turned off (setHorizontalScrollbarPolicy(HORIZONTAL_SCROLLBAR_NEVER) and so on). Then, set up a click or action listener for your elements that calculates the new center point, what the new viewport rectangle coordinates will be, and use scrollRectToVisible on the panel to shift the view. For animation, you can use a Swing Timer to set up a series of incremental scrolls in the required direction until you reach the target.
I am working on an app which when used for loading a file and drawing the contained components, may result into painting of overlapping components. For example, consider a big rectangle box containing text line inside it.
Now because these components are overlapping, it is difficult for the user to select the inner text box in this case as it has been overlapped by the rectangle box.
We were thinking of solving this with allowing the users to actually move any component to a layer below the current one. But this has its own limitations on the usability side, as then for every such case the user will have to move the bigger or the most recently painted component to a layer below and then do the other processing on the inner components like dragging etc. There can be more than 2 components at the same 2d (x & y position) in this app.
I am sure that there should be a better solution for this and could someone please provide some pointers on the implemention part of it.
I am not sure, whether i understand your question. Do you have problems, with the action listeners or because of drawing the components?
This How to Use Root Panes may be helps.
You can create a Glasspane in Java
Here's a simple example of an object drawing program that supports click and drag for multiple selections. More advanced programs often implement z-order functionality (Move Forward, Move Backward, Move to Front, Move to Back) by simply re-ordering the node list.
As an alternative to the layered pane approach, also consider JInternalFrame. This example shows How to Use Actions to manage a menu from which hidden windows may be brought to the fore.