Hello everyone. I'm trying to add some buttons to ...
# tornadofx
a
Hello everyone. I'm trying to add some buttons to the titleRegion of a titledpane, but somehow im struggling to find the right way. Should i look up the titleRegion in the childrens with
getChildList()
or ist there any other suitable way to access it?
r
You should set the
graphic
of the
TitledPane
to a node that contains the buttons (such as an
HBox
)
a
This is what is already tried:
Copy code
class DeviceListFragment : ListCellFragment<Device>() {
	private val appliance = DeviceModel().bindTo(this)

	override val root = titledpane(appliance.name) {

		graphic = hbox {
			button("test") {
				action { <http://log.info|log.info>("asfdsd") }
			}
		}
		addClass(Styles.titledDevicePane)
		add(DeviceFragment(appliance))
	}
}
But this adds the button in the content area and makes the title huge (bigger then the content)
Looks like the mistake was not setting the content correctly and just adding it.
Copy code
graphic = flowpane() {
			alignment = Pos.TOP_RIGHT
			button("test") {
				action { <http://log.info|log.info>("asfdsd") }
			}
		}
		addClass(Styles.titledDevicePane)
		content = hbox { add(DeviceFragment(device)) }
}
Is much more like what i wanted. No the button is correctly displayed. Now i just need to find out how i can put the button to right of the title. At the moment its both in the middle.
Doing it like this did the trick
Copy code
override val root = titledpane() {
		addClass(Styles.titledDevicePane)
		graphic = hbox() {
			alignment = Pos.CENTER
			minWidthProperty().bind(this@titledpane.widthProperty())
			padding = insets(0, 0, 0, 35)

			label(device.name) {
				style {
					fontSize = 1.2.em
				}
			}
			hbox {
				hboxConstraints {
					hgrow = Priority.ALWAYS
					maxWidth = Double.MAX_VALUE
				}
			}
			button(graphic = Styles.closeIcon()) {
				action { <http://log.info|log.info>("asfdsd") }
			}
		}
		content = hbox { add(DeviceFragment(device)) }
	}
https://stackoverflow.com/questions/52457813/javafx-11-add-a-graphic-to-a-titledpane-on-the-right-side I'd guess i focused too much on searching how people did it in tfx and not searching how one could do it in jfx...
r
Unfortunately, mixing the type safe builders with properties can have some unexpected results (as the builders try to add the built nodes directly in the current context).
a
Do you think i could put this up somewhere. In the guide there is a snippets section which is rather empty?
I would love to find more snippets like this one...