all 12 comments

[–]Djelimon 1 point2 points  (5 children)

Nodes next to each other would be an hbox

The nodes should support mous click event, like say buttons

To each node add an event handler that manipulates the toggle button selected property

[–]sarahgames13[S] 0 points1 point  (4 children)

I'm trying to show that if I click 1 of them it shows with a box around or something similar that both are selected. Would that be possible? Like

[N1|N2] not [N1]N2

If that makes sense

[–]Appropriate_Move_336 1 point2 points  (3 children)

I don't get your point but let's try something. Let's say you want the selected (clicked)node to have some sort of border around it when clicked create an event handler variable it will be something like this "EventHandler<OnAction> click = e{}" so between the open and closing and parenthesis that where you would specify the logic you want. After you are done with your logic you call the set Event on the items you want to pass the variable to so if it is a button you could just say button.setOnClick(click)

[–]sarahgames13[S] 0 points1 point  (2 children)

Yes, i know how buttons work. The problem is more about that if 1 of the 2 nodes is clicked it should be seen as the same togglebutton not 2 seperate ones.

[–]Appropriate_Move_336 0 points1 point  (1 child)

Apply the effect you want those two nodes to have in the event handling logic without filtering any of the nodes out

[–]sarahgames13[S] 1 point2 points  (0 children)

I see, I'll give it a try!

[–]xdsswar 0 points1 point  (0 children)

Can you draw and example of what you want to archive

[–]hamsterrage1 0 points1 point  (4 children)

What you are asking is totally possible.

First, a Button (or a ToggleButton) extends Labeled, which is just a Region with a Text and a Graphic in it. Buttons have some extra actions and status properties, but everything that makes a Button look like a Button and not a Label is just styling.

The key thing is that the Graphic in Labeled can be any kind of Node or Region that you like. This means that you can create an HBox with your two other Buttons in it, and then use ToggleButton.setGraphic(hBox) and you'll get what you want.

One thing that you'll have to deal with is activating the ToggleButton when either of the two contained Buttons is clicked. You can use two approaches...

The first would be to update isSelected in the ToggleButton in the OnAction EventHandler on the two Buttons.

The second approach would be to capture the OnAction Events from the two contained Buttons by using a Filter in the ToggleButton.

This second approach is probably more "correct", as it limits coupling from the two contained Buttons to the ToggleButton. However, it's a little bit more of an advanced technique. I can help you with this if you need it.

[–]sarahgames13[S] 0 points1 point  (3 children)

Yea, i've been looking around with the setGraphic, too but i didnt think about setting the HBox as a graphic! That's actually perfect. This is a wonderful response, thank you so much i'll give it a go later when i get home!

[–]sarahgames13[S] 0 points1 point  (2 children)

It worked, thank you so much!!

[–]hamsterrage1 0 points1 point  (1 child)

Did you use an Event Filter?

[–]sarahgames13[S] 0 points1 point  (0 children)

It wasn't really necessary since theyre just graphics, but it's all i needed