Hyperlinks JavaFX
In my previous example, we used a Button to handle the mouse clicks and increment the variable that is displayed on the text label. We could also use hyperlinks to do the same. We do do a lot more with the hyperlinks such as opening a webpage and so on, but we shall retain the previous example for consistency. Here, I shall be using the hyperlinks to increment the value as I mentioned it earlier. The source listing is as follows:
/*
* Main.fx
*
* Created on Dec 11, 2007, 10:52:43 AM
*/
package text;
/**
* @author mithun
*/
import javafx.ui.*;
class ButtonClickModel {
attribute numClicks: Number;
}
var model = new ButtonClickModel();
Frame {
width: 200
height:200
content: GridPanel {
border: EmptyBorder {
top: 30
left: 30
bottom: 30
right: 30
}
rows: 2
columns: 1
vgap: 10
cells:
[Label {
text: bind
"<html>
<a href='{#(operation() {model.numClicks++;})}'>
Click
</a>
</html>"
},
Label {
text: bind "Count: {model.numClicks}"
}]
}
visible: true
};
From the code snippet, you could observe the following:
[Label {
text: bind
"<html>
<a href='{#(operation() {model.numClicks++;})}'>
Click
</a>
</html>"
},
Label {
text: bind "Count: {model.numClicks}"
}]

When you click on the hyperlink a few times, the count gets incremented and is diplayed on the frame as you could see from the following screenshot.

Posted at 11:42AM Dec 11, 2007 by mithun in JavaFX | Comments[0]