I want to get font style(bold, italics...) for the given fonts.
Currently i am getting the font list in a combobox using javafx.scene.text.Font.getFamilies() and now I want to get font style for each font, like that in notepad.
can any one guide me how to get list of those fonts style and use that to set the property for a given TextArea named demo_text_area.
Related
How do I set an IText7 fallback font? That is: A font which is used as a fallback font in cases where the primary font don't have a specific code point.
My original code just used PdfFontFactory.createFont(...) to get a PdfFont, and then I just called setFont on the Text element where I wanted to change font. This worked as in the text was shown with the expected font, but I could not find any way to specify a fallback font.
So I changed my code, so now I start by creating a new FontProvider and then call addFont(...) with all the fonts I need, including the fallback font.
And then I add this font provider to the document.
I then call setFontFamily on the Text objects where I want to change the font, and this works. Including fallback to the first added font, in cases where the primary font don't have the specified codepoint.
But is this the correct way to handle this issue?
This solution does have one new problem. It always embed the fonts in the pdf documents and I can't find a way to prevent this. None of the addFonts or setFontFamily methods have a flag to specify if the font should be embeded.
The FontProvider does have a method called getDefaultEmbeddingFlag() which always return true, so I tried to create a new Class which extended FontProvider and changed getDefaultEmbeddingFlag to just return false. But even when I use this class as FontProvider the font still get embeded.
So I guess my main question is: How do I enable fallback to a different font for unknown code points, while still having the ability not to embed fonts?.
I am looking for a way to print content in JTextComponent's text with multiple fonts and styles.
For example: first Title with bigger font and then some custom text in different style in one component
You can use a JTextPane for this. You can control font, color, bold, size etc.
Read the section from the Swing tutorial on Text Component Features for more information and working examples.
For a another simple example to get you started check out: Is there a way to filter / search for content in a HTMLEditorKit?
The only way that I have learned to change the font of text in java so far is using new Font(font name, Font.PLAIN, font size) and I was wondering if there is a way that I could just simply change the font type while not effecting any other aspects of it. This is because I want to be able to change the font type of all componenets of the GUI using one method using input from a combo box in the settings section of the program and it would be a pain to go back through all of the components and search for their exact font size.
If you have many components, with different font sizes, register a PropertyChangeListener on each component (that displays text) as you create it. Then the propertyChange() method of the listener should get the font of the source and change it using deriveFont() to create a font of the new style.
You can use deriveFont(style) to change the font with a new style. This creates a new Font object.
I have a JEditorPane where I'll copy some text from other application e.g. Adobe Pagemaker, Corel Draw etc. I want to keep my fonts unchanged. How can I do it ?
I want a JEditorPane with different font.
The examples in How to Use Editor Panes and Text Panes may guide you in this. In particular, TextComponentDemo illustrates changing font characteristics both programmatically and interactively. See initDocument() for details.
You have to set it in StyleContext, a default font and then set the StyleContext object for your JEditorPane
Read about StyleContext
How can I set the font/bold/italic/underline whatever of some text in a JEditorPane?
I am trying to create a simple document editor, but i can only figure out how to set the font/bold/italic/whatever of the ENTIRE JEditor/JText pane.
RTF is preferred, HTML is fine as well.
JEditorPane.getDocument() returns an instance of StyledDocument. StyledDocument has setCharacterAttributes() method to set the font properties.
Related example: http://www.java2s.com/Code/JavaAPI/javax.swing/JTextPanesetCharacterAttributesAttributeSetattrbooleanreplace.htm