Skip to content

Commit

Permalink
Improve multi line text UX
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanseter committed Feb 20, 2024
1 parent e32e08c commit 5913cb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.hanseter</groupId>
<artifactId>json-properties-fx</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>

<packaging>bundle</packaging>
<name>JSON Properties Editor Fx</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
package com.github.hanseter.json.editor.controls

import javafx.beans.property.Property
import javafx.scene.control.ScrollPane
import javafx.scene.control.TextArea
import javafx.scene.control.skin.TextAreaSkin

class MultiLineStringControl : ControlWithProperty<String?> {
override val control: TextArea = TextArea().apply {
maxHeight = 26.0
prefHeightProperty().bind(maxHeightProperty())
minHeightProperty().bind(maxHeightProperty())
textProperty().addListener { _, _, text ->
maxHeight = if ('\n' in text) 70.0
else 26.0
if ('\n' in text) {
maxHeight = 70.0
setHorizonzalScrollbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED)
} else {
maxHeight = 26.0
setHorizonzalScrollbarPolicy(ScrollPane.ScrollBarPolicy.NEVER)
}
}
}

private fun TextArea.setHorizonzalScrollbarPolicy(policy: ScrollPane.ScrollBarPolicy) {
((skin as TextAreaSkin).children.single() as ScrollPane).hbarPolicy = policy
}

override val property: Property<String?>
get() = control.textProperty()

Expand Down

0 comments on commit 5913cb3

Please sign in to comment.