A few days ago, I posted a mouse handling related question to the JavaFX GUI mailing list, and Sven Drieling responded with a link to some helpful examples that he created. One of these examples is a program that displays the information that can be retrieved from the MouseEvent object that is passed to the JavaFX mouse event handlers. Here's a screenshot of that application, named MouseEvents.fx:
As shown in the JavaFX SDK Packages are Taking Shape post, the MouseEvent class is located in the new javafx.input package. Take a look at the Check out the JavaFX Script Documentation post to examine the MouseEvent class, as well as the mouse handler methods in the Node class which is located in the javafx.scene package.
Sven's second example demonstrates the mouse cursors that are available via constants in the Cursor class, also located in the javafx.scene package. Here's a screenshot of this program:
Sven's examples have full source code and JNLP links, so go check them out and learn some Mighty Mouse handling. Thanks again, Sven!
Jim Weaver
JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-side Applications
Immediate eBook (PDF) download available at the book's Apress site
You may want to set MouseThreshold1 and 2 a little higher than 0 if
your pointer becomes a little too jumpy on the screen, but make sure
that MouseThreshold2 is greater or equal to MouseThreshold1, and all
three of these are integer values.
Posted by: generic cialis | April 27, 2010 at 03:53 PM
Bill,
Regarding the layout issues, please take a look at the Grid layout in the JFXtras project:
http://javafxpert.com/weblog/2008/12/jfxtras-01-release-utilities-and-addons-for-the-javafx-language.html
Thanks,
Jim Weaver
Posted by: James Weaver | December 31, 2008 at 09:04 AM
So - So example, (Sorry)
My how JavaFX moves fast. His program is only 5 months old. I had to update it and notice now how the combination of HBox, and VBox to lay out the Nodes actually maligns text. Looks like there is some more work to do as far as mouse event handling goes. Look at the last example. The Node.id is not returned.
I found this while trying to find out why I cannot get any response from my app between the time that I press down the middle mouse button until the time I release it.
Oh well, Here is the update code from Svens web page:
/**
* Display mouse events.
*
* @author Sven Drieling
* @version 0.4 (02-Aug-2008)
* @copyright (C) 2008 by Sven Drieling
* @license GPL 2.0
*/
package mouseevents;
import javafx.ext.swing.SwingLabel;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.*;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
var type = '';
var m: MouseEvent;
Stage {
title: "Mouse: Display MouseEvents"
scene: Scene {
width: 390
height: 700
content: [
VBox{
spacing: 20
content:[
Rectangle{
x: 20
y: 20
width: 350
height: 200
fill: Color.BLUE
onMouseClicked: function (e: MouseEvent) {
type = 'onMouseClicked';
m = e;
}// onMouseClicked
onMouseDragged: function (e: MouseEvent) {
type = 'onMouseDragged';
m = e;
}// onMouseDragged
onMouseEntered: function (e: MouseEvent) {
type = 'onMouseEntered';
m = e;
}// onMouseEntered
onMouseExited: function (e: MouseEvent) {
type = 'onMouseExited';
m = e;
}// onMouseExited
onMouseMoved: function (e: MouseEvent) {
type = 'onMouseMoved';
m = e;
}// onMouseMoved
onMousePressed: function (e: MouseEvent) {
type = 'onMousePressed';
m = e;
}// onMousePressed
onMouseReleased: function (e: MouseEvent) {
type = 'onMouseReleased';
m = e;
}// onMouseReleased
onMouseWheelMoved: function (e: MouseEvent) {
type = 'onMouseWheelMoved';
m = e;
}// onMouseWheelMoved
},// Rectangle
HBox{
spacing:6
content: [VBox{
spacing: 6
content:[
SwingLabel {
text: 'Type'},
SwingLabel {
text: 'Button'},
SwingLabel {
text: 'ClickCount'},
SwingLabel {
text: 'WheelRotation'},
SwingLabel {
text: 'ScreenX/Y'},
SwingLabel {
text: 'X/Y'},
SwingLabel {
text: 'SceneX/Y'},
SwingLabel {
text: 'DragX/Y'},
SwingLabel {
text: 'AltDown'},
SwingLabel {
text: 'ControlDown'},
SwingLabel {
text: 'MetaDown'},
SwingLabel {
text: 'ShiftDown'},
SwingLabel {
text: 'PopupTrigger'},
SwingLabel {
text: 'PrimaryButtonDown'},
SwingLabel {
text: 'MiddleButtonDown'},
SwingLabel {
text: 'SecondaryButtonDown'},
SwingLabel {
text: 'Node.id'}
]//content
},// VBox
VBox{
spacing: 7
content: [
SwingLabel {
text: bind "{type}"},
SwingLabel {
text: bind "{m.button}"},
SwingLabel {
text: bind "{m.clickCount}"},
SwingLabel {
text: bind "{m.wheelRotation}"},
SwingLabel {
text: bind "{m.screenX}/{m.screenY}"},
SwingLabel {
text: bind "{m.x}/{m.y}"},
SwingLabel {
text: bind "{m.sceneX}/{m.sceneY}"},
SwingLabel {
text: bind "{m.dragX}/{m.dragY}"},
SwingLabel {
text: bind "{m.altDown}"},
SwingLabel {
text: bind "{m.controlDown}"},
SwingLabel {
text: bind "{m.metaDown}"},
SwingLabel {
text: bind "{m.shiftDown}"},
SwingLabel {
text: bind "{m.popupTrigger}"},
SwingLabel {
text: bind "{m.primaryButtonDown}"
},
SwingLabel {
text: bind "{m.middleButtonDown}"
},
SwingLabel {
text: bind "{m.secondaryButtonDown}"
},
SwingLabel {
text: bind "{m.node.id}"
}
]//content
}// VBox
]//content
}// Hbox
]// content
}, //VBox
]// content
}// Scene
}// Stage
Posted by: Bill Thayer | December 30, 2008 at 04:21 PM
The mighty mouse examples are cool. :)
Posted by: Online Gambling | July 23, 2008 at 01:18 AM