Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can i disable vertical scrolling and always show the whole text? #674

Closed
2fchar opened this issue Jan 28, 2018 · 6 comments
Closed

how can i disable vertical scrolling and always show the whole text? #674

2fchar opened this issue Jan 28, 2018 · 6 comments
Labels

Comments

@2fchar
Copy link

2fchar commented Jan 28, 2018

i was using TextFlow as a cell in ListView, and make it always expand horizontally.
so texts are always as wide as the parent, and if they don't fit in one line, they wrap, take up multiple lines, take up whatever vertical space is needed, all texts are visible all the time

but TextFlow misses features, for example, i'm told the easiest way to make text selectable is to use RichTextFX

RichTextFX is powerful, but maybe too powerful, now when the text is too long, a built-in scroll mechanism kicks in. i searched around, i guess i can make it ignore certain mouse events, but i don't think that'll make the text always shown in its entirety on screen, right?

could you give me some pointers, thanks!

@2fchar 2fchar changed the title how can i disable scrolling and make it more like TextFlow? how can i disable scrolling and always show the whole text? Jan 29, 2018
@JordanMartinez
Copy link
Contributor

RichTextFX is powerful, but maybe too powerful, now when the text is too long, a built-in scroll mechanism kicks in.

Yes, because that's what is expected for regular text editors.

It sounds like you want to wrap the text so that the horizontal scrollbar never appears, correct? If so, have you turned on the text wrapping (e.g. area.setWrapText(true))?

I'm also assuming that you don't want the vertical scrollbar to stop appearing or vertical scrolling to stop working at all, correct?

@2fchar
Copy link
Author

2fchar commented Jan 30, 2018

@JordanMartinez Yes, I have turned on the text wrapping and got rid of the horizontal scrollbar. Also I want to completely get rid of the vertical scrolling, because actually I just want a more powerful TextFlow instead of a text editor.
I want it to shrink or expand vertically depending on how much content is currently put inside it.
I know RichTextFX is primarily designed for editors, but it looks quite flexible, I guess it can be made to work in many situations.

Thanks for your quick reply!

@2fchar 2fchar changed the title how can i disable scrolling and always show the whole text? how can i disable vertical scrolling and always show the whole text? Jan 30, 2018
@JordanMartinez
Copy link
Contributor

Also I want to completely get rid of the vertical scrolling

Sorry. I misread the issue's title where you explicitly state that, haha. See OverrideBehaviorDemo to know how to override the default scrolling behavior and then check out GenericStyledAreaBehavior to see what specifically you need to override to prevent the vertical scrolling from occurring. You might also need to override some of the mouse behavior hooks (e.g. onSelectionDrop(Consumer<MouseEvent>) in GenericStyledArea) as that may also scroll the viewport at times.

I want it to shrink or expand vertically depending on how much content is currently put inside it.

I think you mean #77

@JordanMartinez
Copy link
Contributor

Since the behavior overriding is a FAQ, I've added my slight variation of my response above to a page in the wiki.

@aimozg
Copy link

aimozg commented Oct 14, 2018

I have similar problem as @trapchar - I want an auto-sizeable, non-scrolling, editable rich text area inside a list cell.

For auto-sizing, I override the computePrefHeight: (Kotlin language)

override fun computePrefHeight(width: Double): Double {
	val ih = insets.top + insets.bottom
	val c = children.firstOrNull() as? VirtualFlow<*, *>
	if (c != null && paragraphs.size > 0) {
		return ih + (0 until paragraphs.size).sumByDouble { i ->
			c.getCell(i).node.prefHeight(width)
		}
	}
	val d = totalHeightEstimateProperty().value
	if (d != null) return ih + d
	runLater { requestLayout() }
}

Scroll events are consumed by VirtualFlow, not Behaviour: https://github.com/FXMisc/Flowless/blob/master/src/main/java/org/fxmisc/flowless/VirtualFlow.java#L185
so I re-fire the event to parent on capture stage

addEventFilter(ScrollEvent.SCROLL) {
	it.consume()
	parent?.fireEvent(it.copyFor(it.source, parent))
}

@xulihang
Copy link
Contributor

xulihang commented Aug 9, 2020

My steps:

  1. set WrapText to be true
  2. call totalHeightEstimate to adjust height
  3. filter scroll event for the textarea and pass it to its parent(e.g. listview).

@Jugen Jugen mentioned this issue Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants