Node position in TreeView
How can I get the position of a node from a TreeView with onclick event in JavaFX?
Let's say when I click on the node (dolor sit amet,) selected with the black circle how can I get the position?
I have tried this with an event when a node is expanded:
root.addEventHandler(EventType.ROOT, (Event event) -> {
if (event.getEventType().getName().equals("BranchExpandedEvent")) {
TreeItem item = (TreeItem) event.getSource();
//here I want to know item position
}
});
java javafx
add a comment |
How can I get the position of a node from a TreeView with onclick event in JavaFX?
Let's say when I click on the node (dolor sit amet,) selected with the black circle how can I get the position?
I have tried this with an event when a node is expanded:
root.addEventHandler(EventType.ROOT, (Event event) -> {
if (event.getEventType().getName().equals("BranchExpandedEvent")) {
TreeItem item = (TreeItem) event.getSource();
//here I want to know item position
}
});
java javafx
there is no item position, there's a cell position that has the item - please read a basic tutorial to learn how to implement and configure custom TreeCells
– kleopatra
Nov 27 '18 at 10:51
What do you want to do with the position(x,y) ? be specific.
– Calips
Nov 27 '18 at 12:17
@Calips I want to have this position and to add some other Nodes (Vertical line in my case to connect the treeitems at the same level) in the TreeView.
– ASTeam
Nov 27 '18 at 20:05
@kleopatra Can you give me some suggestion about that. To let you know I have done some of my CustomCell that extend TreeCell using the HBox widget, not so much success to achieve something out of the TreeItems so a Vertical Line that goes on top of them which should not be connected with TreeItems but only with the TreeView.
– ASTeam
Nov 27 '18 at 20:05
add a comment |
How can I get the position of a node from a TreeView with onclick event in JavaFX?
Let's say when I click on the node (dolor sit amet,) selected with the black circle how can I get the position?
I have tried this with an event when a node is expanded:
root.addEventHandler(EventType.ROOT, (Event event) -> {
if (event.getEventType().getName().equals("BranchExpandedEvent")) {
TreeItem item = (TreeItem) event.getSource();
//here I want to know item position
}
});
java javafx
How can I get the position of a node from a TreeView with onclick event in JavaFX?
Let's say when I click on the node (dolor sit amet,) selected with the black circle how can I get the position?
I have tried this with an event when a node is expanded:
root.addEventHandler(EventType.ROOT, (Event event) -> {
if (event.getEventType().getName().equals("BranchExpandedEvent")) {
TreeItem item = (TreeItem) event.getSource();
//here I want to know item position
}
});
java javafx
java javafx
asked Nov 27 '18 at 10:19
ASTeamASTeam
178211
178211
there is no item position, there's a cell position that has the item - please read a basic tutorial to learn how to implement and configure custom TreeCells
– kleopatra
Nov 27 '18 at 10:51
What do you want to do with the position(x,y) ? be specific.
– Calips
Nov 27 '18 at 12:17
@Calips I want to have this position and to add some other Nodes (Vertical line in my case to connect the treeitems at the same level) in the TreeView.
– ASTeam
Nov 27 '18 at 20:05
@kleopatra Can you give me some suggestion about that. To let you know I have done some of my CustomCell that extend TreeCell using the HBox widget, not so much success to achieve something out of the TreeItems so a Vertical Line that goes on top of them which should not be connected with TreeItems but only with the TreeView.
– ASTeam
Nov 27 '18 at 20:05
add a comment |
there is no item position, there's a cell position that has the item - please read a basic tutorial to learn how to implement and configure custom TreeCells
– kleopatra
Nov 27 '18 at 10:51
What do you want to do with the position(x,y) ? be specific.
– Calips
Nov 27 '18 at 12:17
@Calips I want to have this position and to add some other Nodes (Vertical line in my case to connect the treeitems at the same level) in the TreeView.
– ASTeam
Nov 27 '18 at 20:05
@kleopatra Can you give me some suggestion about that. To let you know I have done some of my CustomCell that extend TreeCell using the HBox widget, not so much success to achieve something out of the TreeItems so a Vertical Line that goes on top of them which should not be connected with TreeItems but only with the TreeView.
– ASTeam
Nov 27 '18 at 20:05
there is no item position, there's a cell position that has the item - please read a basic tutorial to learn how to implement and configure custom TreeCells
– kleopatra
Nov 27 '18 at 10:51
there is no item position, there's a cell position that has the item - please read a basic tutorial to learn how to implement and configure custom TreeCells
– kleopatra
Nov 27 '18 at 10:51
What do you want to do with the position(x,y) ? be specific.
– Calips
Nov 27 '18 at 12:17
What do you want to do with the position(x,y) ? be specific.
– Calips
Nov 27 '18 at 12:17
@Calips I want to have this position and to add some other Nodes (Vertical line in my case to connect the treeitems at the same level) in the TreeView.
– ASTeam
Nov 27 '18 at 20:05
@Calips I want to have this position and to add some other Nodes (Vertical line in my case to connect the treeitems at the same level) in the TreeView.
– ASTeam
Nov 27 '18 at 20:05
@kleopatra Can you give me some suggestion about that. To let you know I have done some of my CustomCell that extend TreeCell using the HBox widget, not so much success to achieve something out of the TreeItems so a Vertical Line that goes on top of them which should not be connected with TreeItems but only with the TreeView.
– ASTeam
Nov 27 '18 at 20:05
@kleopatra Can you give me some suggestion about that. To let you know I have done some of my CustomCell that extend TreeCell using the HBox widget, not so much success to achieve something out of the TreeItems so a Vertical Line that goes on top of them which should not be connected with TreeItems but only with the TreeView.
– ASTeam
Nov 27 '18 at 20:05
add a comment |
1 Answer
1
active
oldest
votes
The Node
you're talking about is known as the disclosureNode
and is accessible via the TreeCell
.
The disclosure node is commonly seen represented as a triangle that rotates on screen to indicate whether or not the TreeItem that it is placed beside is expanded or collapsed.
You can get the position of this Node
with properties such as Node.boundsInLocal
or Node.boundsInParent
. There are also methods in Node
to help convert between coordinate spaces (e.g. localToScene
, sceneToLocal
, etc...).
Also, the following code is suspect:
root.addEventHandler(EventType.ROOT, (Event event) -> {
if (event.getEventType().getName().equals("BranchExpandedEvent")) {
}
});
You shouldn't need to check the name of the EventType
. Instead, register the EventHandler
for the EventType
you want to listen for—in this case, TreeItem.branchExpandedEvent()
. For example, if your TreeItem
s have values of type String
:
// "root" is a TreeItem<String>
// "event" is a TreeItem.TreeModificationEvent<String>
root.addEventHandler(TreeItem.<String>branchExpandedEvent(), event -> {
// do something...
});
If you must check the EventType
inside the EventHandler
then test that the EventType
s are equal, not their names; it's less error-prone.
root.addEventHandler(Event.ANY, event -> {
if (event.getEventType().equals(TreeItem.branchExpandedEvent()) {
// do something...
}
});
I want to have this position and to add some other Nodes (Vertical line in my case to connect the treeitems at the same level) in the TreeView.
I haven't looked into it, but this sounds like it should be implemented by the TreeCell
. The TreeItem
shouldn't know much, if anything, about the view. In other words, handling this inside an event handler added to the root TreeItem
seems like the wrong place. Note, you can get the expanded status of a TreeItem
from within a TreeCell
as it has access to its TreeItem
.
I have problems accessing the TreeCell from the TreeItem. In the event, I can get easily the TreeItemTreeItem item = (TreeItem) event.getSource();
. How to access the TreeCell in order to access the disclosureNode and to use the properties of it.
– ASTeam
Nov 28 '18 at 11:43
You likely can't from theTreeItem
. You can use your ownTreeCell
implementation by setting theTreeView.cellFactory
property. You may need to subclassTreeCellSkin
as well.
– Slaw
Nov 28 '18 at 21:52
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53497433%2fnode-position-in-treeview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The Node
you're talking about is known as the disclosureNode
and is accessible via the TreeCell
.
The disclosure node is commonly seen represented as a triangle that rotates on screen to indicate whether or not the TreeItem that it is placed beside is expanded or collapsed.
You can get the position of this Node
with properties such as Node.boundsInLocal
or Node.boundsInParent
. There are also methods in Node
to help convert between coordinate spaces (e.g. localToScene
, sceneToLocal
, etc...).
Also, the following code is suspect:
root.addEventHandler(EventType.ROOT, (Event event) -> {
if (event.getEventType().getName().equals("BranchExpandedEvent")) {
}
});
You shouldn't need to check the name of the EventType
. Instead, register the EventHandler
for the EventType
you want to listen for—in this case, TreeItem.branchExpandedEvent()
. For example, if your TreeItem
s have values of type String
:
// "root" is a TreeItem<String>
// "event" is a TreeItem.TreeModificationEvent<String>
root.addEventHandler(TreeItem.<String>branchExpandedEvent(), event -> {
// do something...
});
If you must check the EventType
inside the EventHandler
then test that the EventType
s are equal, not their names; it's less error-prone.
root.addEventHandler(Event.ANY, event -> {
if (event.getEventType().equals(TreeItem.branchExpandedEvent()) {
// do something...
}
});
I want to have this position and to add some other Nodes (Vertical line in my case to connect the treeitems at the same level) in the TreeView.
I haven't looked into it, but this sounds like it should be implemented by the TreeCell
. The TreeItem
shouldn't know much, if anything, about the view. In other words, handling this inside an event handler added to the root TreeItem
seems like the wrong place. Note, you can get the expanded status of a TreeItem
from within a TreeCell
as it has access to its TreeItem
.
I have problems accessing the TreeCell from the TreeItem. In the event, I can get easily the TreeItemTreeItem item = (TreeItem) event.getSource();
. How to access the TreeCell in order to access the disclosureNode and to use the properties of it.
– ASTeam
Nov 28 '18 at 11:43
You likely can't from theTreeItem
. You can use your ownTreeCell
implementation by setting theTreeView.cellFactory
property. You may need to subclassTreeCellSkin
as well.
– Slaw
Nov 28 '18 at 21:52
add a comment |
The Node
you're talking about is known as the disclosureNode
and is accessible via the TreeCell
.
The disclosure node is commonly seen represented as a triangle that rotates on screen to indicate whether or not the TreeItem that it is placed beside is expanded or collapsed.
You can get the position of this Node
with properties such as Node.boundsInLocal
or Node.boundsInParent
. There are also methods in Node
to help convert between coordinate spaces (e.g. localToScene
, sceneToLocal
, etc...).
Also, the following code is suspect:
root.addEventHandler(EventType.ROOT, (Event event) -> {
if (event.getEventType().getName().equals("BranchExpandedEvent")) {
}
});
You shouldn't need to check the name of the EventType
. Instead, register the EventHandler
for the EventType
you want to listen for—in this case, TreeItem.branchExpandedEvent()
. For example, if your TreeItem
s have values of type String
:
// "root" is a TreeItem<String>
// "event" is a TreeItem.TreeModificationEvent<String>
root.addEventHandler(TreeItem.<String>branchExpandedEvent(), event -> {
// do something...
});
If you must check the EventType
inside the EventHandler
then test that the EventType
s are equal, not their names; it's less error-prone.
root.addEventHandler(Event.ANY, event -> {
if (event.getEventType().equals(TreeItem.branchExpandedEvent()) {
// do something...
}
});
I want to have this position and to add some other Nodes (Vertical line in my case to connect the treeitems at the same level) in the TreeView.
I haven't looked into it, but this sounds like it should be implemented by the TreeCell
. The TreeItem
shouldn't know much, if anything, about the view. In other words, handling this inside an event handler added to the root TreeItem
seems like the wrong place. Note, you can get the expanded status of a TreeItem
from within a TreeCell
as it has access to its TreeItem
.
I have problems accessing the TreeCell from the TreeItem. In the event, I can get easily the TreeItemTreeItem item = (TreeItem) event.getSource();
. How to access the TreeCell in order to access the disclosureNode and to use the properties of it.
– ASTeam
Nov 28 '18 at 11:43
You likely can't from theTreeItem
. You can use your ownTreeCell
implementation by setting theTreeView.cellFactory
property. You may need to subclassTreeCellSkin
as well.
– Slaw
Nov 28 '18 at 21:52
add a comment |
The Node
you're talking about is known as the disclosureNode
and is accessible via the TreeCell
.
The disclosure node is commonly seen represented as a triangle that rotates on screen to indicate whether or not the TreeItem that it is placed beside is expanded or collapsed.
You can get the position of this Node
with properties such as Node.boundsInLocal
or Node.boundsInParent
. There are also methods in Node
to help convert between coordinate spaces (e.g. localToScene
, sceneToLocal
, etc...).
Also, the following code is suspect:
root.addEventHandler(EventType.ROOT, (Event event) -> {
if (event.getEventType().getName().equals("BranchExpandedEvent")) {
}
});
You shouldn't need to check the name of the EventType
. Instead, register the EventHandler
for the EventType
you want to listen for—in this case, TreeItem.branchExpandedEvent()
. For example, if your TreeItem
s have values of type String
:
// "root" is a TreeItem<String>
// "event" is a TreeItem.TreeModificationEvent<String>
root.addEventHandler(TreeItem.<String>branchExpandedEvent(), event -> {
// do something...
});
If you must check the EventType
inside the EventHandler
then test that the EventType
s are equal, not their names; it's less error-prone.
root.addEventHandler(Event.ANY, event -> {
if (event.getEventType().equals(TreeItem.branchExpandedEvent()) {
// do something...
}
});
I want to have this position and to add some other Nodes (Vertical line in my case to connect the treeitems at the same level) in the TreeView.
I haven't looked into it, but this sounds like it should be implemented by the TreeCell
. The TreeItem
shouldn't know much, if anything, about the view. In other words, handling this inside an event handler added to the root TreeItem
seems like the wrong place. Note, you can get the expanded status of a TreeItem
from within a TreeCell
as it has access to its TreeItem
.
The Node
you're talking about is known as the disclosureNode
and is accessible via the TreeCell
.
The disclosure node is commonly seen represented as a triangle that rotates on screen to indicate whether or not the TreeItem that it is placed beside is expanded or collapsed.
You can get the position of this Node
with properties such as Node.boundsInLocal
or Node.boundsInParent
. There are also methods in Node
to help convert between coordinate spaces (e.g. localToScene
, sceneToLocal
, etc...).
Also, the following code is suspect:
root.addEventHandler(EventType.ROOT, (Event event) -> {
if (event.getEventType().getName().equals("BranchExpandedEvent")) {
}
});
You shouldn't need to check the name of the EventType
. Instead, register the EventHandler
for the EventType
you want to listen for—in this case, TreeItem.branchExpandedEvent()
. For example, if your TreeItem
s have values of type String
:
// "root" is a TreeItem<String>
// "event" is a TreeItem.TreeModificationEvent<String>
root.addEventHandler(TreeItem.<String>branchExpandedEvent(), event -> {
// do something...
});
If you must check the EventType
inside the EventHandler
then test that the EventType
s are equal, not their names; it's less error-prone.
root.addEventHandler(Event.ANY, event -> {
if (event.getEventType().equals(TreeItem.branchExpandedEvent()) {
// do something...
}
});
I want to have this position and to add some other Nodes (Vertical line in my case to connect the treeitems at the same level) in the TreeView.
I haven't looked into it, but this sounds like it should be implemented by the TreeCell
. The TreeItem
shouldn't know much, if anything, about the view. In other words, handling this inside an event handler added to the root TreeItem
seems like the wrong place. Note, you can get the expanded status of a TreeItem
from within a TreeCell
as it has access to its TreeItem
.
edited Nov 28 '18 at 0:39
answered Nov 28 '18 at 0:16
SlawSlaw
8,75631234
8,75631234
I have problems accessing the TreeCell from the TreeItem. In the event, I can get easily the TreeItemTreeItem item = (TreeItem) event.getSource();
. How to access the TreeCell in order to access the disclosureNode and to use the properties of it.
– ASTeam
Nov 28 '18 at 11:43
You likely can't from theTreeItem
. You can use your ownTreeCell
implementation by setting theTreeView.cellFactory
property. You may need to subclassTreeCellSkin
as well.
– Slaw
Nov 28 '18 at 21:52
add a comment |
I have problems accessing the TreeCell from the TreeItem. In the event, I can get easily the TreeItemTreeItem item = (TreeItem) event.getSource();
. How to access the TreeCell in order to access the disclosureNode and to use the properties of it.
– ASTeam
Nov 28 '18 at 11:43
You likely can't from theTreeItem
. You can use your ownTreeCell
implementation by setting theTreeView.cellFactory
property. You may need to subclassTreeCellSkin
as well.
– Slaw
Nov 28 '18 at 21:52
I have problems accessing the TreeCell from the TreeItem. In the event, I can get easily the TreeItem
TreeItem item = (TreeItem) event.getSource();
. How to access the TreeCell in order to access the disclosureNode and to use the properties of it.– ASTeam
Nov 28 '18 at 11:43
I have problems accessing the TreeCell from the TreeItem. In the event, I can get easily the TreeItem
TreeItem item = (TreeItem) event.getSource();
. How to access the TreeCell in order to access the disclosureNode and to use the properties of it.– ASTeam
Nov 28 '18 at 11:43
You likely can't from the
TreeItem
. You can use your own TreeCell
implementation by setting the TreeView.cellFactory
property. You may need to subclass TreeCellSkin
as well.– Slaw
Nov 28 '18 at 21:52
You likely can't from the
TreeItem
. You can use your own TreeCell
implementation by setting the TreeView.cellFactory
property. You may need to subclass TreeCellSkin
as well.– Slaw
Nov 28 '18 at 21:52
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53497433%2fnode-position-in-treeview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
there is no item position, there's a cell position that has the item - please read a basic tutorial to learn how to implement and configure custom TreeCells
– kleopatra
Nov 27 '18 at 10:51
What do you want to do with the position(x,y) ? be specific.
– Calips
Nov 27 '18 at 12:17
@Calips I want to have this position and to add some other Nodes (Vertical line in my case to connect the treeitems at the same level) in the TreeView.
– ASTeam
Nov 27 '18 at 20:05
@kleopatra Can you give me some suggestion about that. To let you know I have done some of my CustomCell that extend TreeCell using the HBox widget, not so much success to achieve something out of the TreeItems so a Vertical Line that goes on top of them which should not be connected with TreeItems but only with the TreeView.
– ASTeam
Nov 27 '18 at 20:05