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

Question: Getting font size of the CodeArea #1228

Open
KoblizekXD opened this issue May 17, 2024 · 3 comments
Open

Question: Getting font size of the CodeArea #1228

KoblizekXD opened this issue May 17, 2024 · 3 comments

Comments

@KoblizekXD
Copy link

Hello, I'm currently building an application which requires me to use CodeArea and I would like to implement mouse wheel scrolling zoom, therefore I need to get a actualy font size and increase/decrease it. I didn't find any method to get that, as getFont() doesn't seem to exist. From what I've yet understood, the font size value can be stored in CSS like this:

.styled-text-area .text {
    -fx-font-size: 24pt;
}

But I'm not really sure how could I retrieve it! I will be grateful for any response! Thanks!

@PavelTurk
Copy link
Contributor

@KoblizekXD I would do it this way:

.styled-text-area .text {
    -fx-font-size: 1em;
}
....
textArea.setStyle("-fx-font-size:" + size);

By other words you need to keep size in some variable.

@KoblizekXD
Copy link
Author

I see what you mean. The thing is now, that I would like to change font size of the actual text when zooming, using CodeArea#setStyle won't work as expected. It will only change the size of line numbers, but not the text itself. How can I do that?

@Jugen
Copy link
Collaborator

Jugen commented May 20, 2024

This can't be done using CodeArea because it extends StyleClassedTextArea which uses CSS style classes that cannot be changed dynamically. To do what you want (using the technique suggested by @PavelTurk) you need to use InlineCssTextArea instead but creating your own CodeArea to extend that is not straightforward.

An alternative idea is to maybe set the scale on the CodeArea instead ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants