-
Notifications
You must be signed in to change notification settings - Fork 236
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 To Add Padding Between StyledTextArea And Text Contents? #394
Comments
See https://github.com/TomasMikula/RichTextFX/wiki/RichTextFX-CSS-Reference-Guide for why that's happening and its fix |
@gbmhunter See issue: #255 (comment) |
Thanks, @JordanMartinez and @kuc I tried the code:
and that worked for the first and last paragraphs, but when I wanted the padding to apply to all paragraphs, the CSS:
didn't work (not even for the first and last, and no other changes). |
@gbmhunter Right, because that's what @kuc was trying to do in his issue: add padding to only the first and last lines in the area. If I'm understanding you correctly, you want something like this....
....where the first line displayed (not just the first line of the text) has space between itself and the top edge of the viewport and the last line displayed (not just the last line of the text) has space between itself and the bottom edge of the viewport, correct? If so, try this css. It's never been tested to see if it works because we never had someone with your issue before (I mention this issue in the layout section of the above CSS Reference Guide link): .virtual-flow {
-fx-padding: 10;
} If the above CSS works, I would guess that it will screw up the behavior handling (e.g. you will click at point (x,y) but it will put the caret at (x+10, y+10). |
Edited to make example also use scroll bars Another workaround, and probably better than the one I mentioned above, is to do what Tomas described in his comment in Kuc's issue: wrap the area in a pane and apply padding to that pane: public class VirtualPane<V extends Virtualized> extends Pane implements Virtualized {
Virtualized content;
public VirtualPane(V content) {
this.content = content;
}
// for every Virtualized method, you'd need to adjust the value
// in light of the pane's padding values
}
VirtualPane pane = new VirtualPane(area);
pane.setPadding(new Insets(10)); |
Yes, sorry if I wasn't clear, I provided the CSS that just modified the first and last paragraph as an example of it working, before removing the I will try those methods. Will the code:
make the scroll-bars look strange, because they now won't extend to the edge of the |
Mm... whoops! I forgot about VirtualizedScrollPane.... Yes, the second approach would be problematic because the code would actually look like this: StyledTextArea area = //
VirtualizedScrollPane<StyledTextArea> vsPane = new VirtualizedScrollPane<>(area);
VirtualPane pane = new VirtualPane(vsPane);
pane.setPadding(new Insets(10)); Even if you add padding to the |
Following works for me:
|
@gbmhunter maybe there is another rule in your CSS that overwrites the padding of the middle paragraphs. Try moving the three rules to the end of your CSS. |
They are at the end as far as I can tell. Could it be something to do with the fact that I am adding text to the
Those
|
@gbmhunter I will tell you what I am using. CSS (Important:
Java (simplified):
|
There is a problem when padding is applied, which I fixed in PR #396 |
@kuc why is the order of |
@kuc forget my question. Just after writing it I realized the reason. It is for the case that the text area contains only one line. |
@JFormDesigner Yep, exactly. |
@kuc , the only thing I seem to be doing differently is that I'm using a |
@gbmhunter BTW: I'm using |
@gbmhunter Maybe when trying to set color you are overwriting padding settings, or something other is wrong with your custom implementation - just a wild guess. |
I am now using an |
Well, it's time for using more powerful weapons - try using ScenicView for debugging. |
ScenicView is great! It gives you debugging access into JavaFX much like Chrome does with web pages. I have used that and found nothing strange. The lines of text all seem to be in the appropriate nodes, and the style class names are set correctly. |
Why not try creating a basic example that we can modify until it works? |
@gbmhunter Any updates on this? |
@JordanMartinez ah sorry no, I have just left it with no padding for the moment and moved on. |
@gbmhunter Can you post your CSS? And are you by chance using IDs (e.g. |
@gbmhunter Now that #510 has been merged, this should now be doable with one line: .styled-text-are {
-fx-padding: 20 px;
} |
@JordanMartinez , I checked out the other pull-request, the fix looks good, thanks for all the hard work put into this!!! I probably won't switch back any time soon (currently using a JavaFX With more and more improvements like this the WebView rich text solution is less needed! |
@gbmhunter No worries! I'm sure any switch would take a lot of time. Besides, the API might change in future versions, so I'd wait until a new stable release was made. |
I have tried the obvious:
styledTextArea.setPadding(new Insets(10, 10, 10, 10));
but it doesn't seem to work. What is the correct way to add padding between a
StyledTextArea
and the textual content that it displays?The text was updated successfully, but these errors were encountered: