Sam
Sam

Reputation: 1304

TornadoFX Fragment OpenWindow is always on top

I'm working with TornadoFX's fragment class, and opening each new fragment within a new window using it's openWindow() method.

The window opens and everything works well. I've set the modality to Modality.NONE so the original screen can be accessed while the new fragment is active.

The problem that I'm having is that the new window is always on top, so I have to move it to access the original window underneath which isn't ideal.

Is this by design/is there anyway to change this behaviour?

I've been playing around with the openWindow()s owner = parameter, setting it to null and another Stage but nothing seems to work.

First, the code that opens the window, view is the fragment.

//h here is just the histogram, an int[] 
val hisScope = HistogramScope(h, pointerVM.APUFile.file.name)

//view declared using the find method.
val view = find<Histogram>(hisScope)

view.whenUndocked {
  closeChart(pointerVM)
}

//code checks to see if the requested histogram is already open
val matchingRnameHistograms = isMatchingRnameOpen(pointerVM)

if (map.size == 0 || matchingRnameHistograms.isEmpty()) {

view.openWindow(stageStyle = StageStyle.UTILITY, modality = Modality.NONE, resizable = false, owner = null, block = false)

map.put(pointerVM, view) //record which histograms are open

} else { //.. not too relevant }

Next, this is how i've declared the fragment with the scope:

class Histogram : Fragment() {

override val scope = super.scope as HistogramScope

override val root = hbox{

    hgrow = Priority.ALWAYS
    vgrow = Priority.ALWAYS

    style{
        minWidth = 1280.px
        minHeight = 250.px
    }

}

Thanks in advance!

Upvotes: 0

Views: 1126

Answers (1)

Edvin Syse
Edvin Syse

Reputation: 7297

When you open a new window in context of another, the owner attribute is by default set to the originating UIComponent. You can pass owner = null to openWindow to prevent this, thus allowing the window to be placed below the originating one. Here is a complete app showing how this works:

class MyApp : App(MainView::class)

class MainView : View() {
    override val root = stackpane {
        setPrefSize(800.0, 600.0)
        button("Open new window").action {
            find<NewWindow>().openWindow(owner = null)
        }
    }
}

class NewWindow : Fragment() {
    override val root = label("I'm not modal!")
}

If you still can't get it to work, try to reduce the number of factors in your code :)

enter image description here

Upvotes: 1

Related Questions