Can you describe what works and doesn’t work, and what you have done to try to resolve it? You’re much more likely to get an answer if you provide information beyond the code itself.
It’s not quite easy to explain what it does and what does not work, but let me try:
TitledPaneToggleAdapter is an adapter that allows for TitledPanes to be handled like RadioButtons or RadioMenuItems within a ToggleGroup. Added to a ToggleGroup only one of the TitledPanes shall be allowed to be expanded; if another TitledPane is triggered to expand, the already expanded one shall collapse.
The Java implementation does what it is supposed to do; however, the Scala implementation is not, it does not anything but I don’t see why, to be the migration of the Java code to Scala is correct, and that’s why I started to wonder that my assessment is wrong.
I just tried it: Unfortunately doesn’t change a thing.
Update: To rule out that the implementation where TitledPaneToggleAdapter is used is the problem, I briefly included the Java variant, and it works fine with that. So there must be some problem with my Scala code.
The titledPane argument being passed in is not assigned to anything in your Adapter.
You’d need to do the equivalent of the java initial assignment on the constructor.
To do so you can
a. define a private val _titledPane = titledPane in your class and then refer to _titledPane in all your methods.
b. obtain the same effect by changing the input parameter in the signature to private val as in class TitledPaneToggleAdapter(private val titledPane: TitledPaned) extends Toggle {...}
I’m not guaranteeing this will solve your faulty behaviour, but it would be more adherent to the original code.
Which could actually change things, since you might not be modifying the correct instance?
In the code after the most recent edit, you will probably want to replace the override def with override val:
// current
override def toggleGroupProperty(): ObjectProperty[ToggleGroup] = new SimpleObjectProperty[ToggleGroup]()
// should be
override val toggleGroupProperty(): ObjectProperty[ToggleGroup] = new SimpleObjectProperty[ToggleGroup]()
As to the converter: IntelliJ is capable of converting code on the fly, and a quick google search turned up http://javatoscala.com/ (not up-to date at all, but may be a starting point)
Wouldn’t have hoped so - but any future reader trying to analyze the code from your example will have a greater chance to spot the issue if they don’t stumble over that unrelated, though obvious, difference - so I thought I’d state the obvious.
After all, without the full code, this will have to be an incremental improvement towards the Java and Scala code being as close to each other as possible.
Sorry for bothering again: You seem to have accidentally turned the wrong method into a val.
The code as it is now still creates a fresh new SimpleObjectProperty[ToggleGroup]() every time the method toggleGroupProperty() is called - effectively losing any state that is ever assigned to it.