Where do they dream up these object names? Never mind...
We had a program where we used a bunch of styles in a Document in a JTextPane. Everything worked fine until they wanted us to make a modification to use two different fonts. The original code that they provided was something like:
[code=java]
protected void setStyles(JText Pane textPane)
{
Style SansSerifFontSt yle =
StyleContext.ge tDefaultStyleCo ntext().getStyl e
(StyleContext.D EFAULT_STYLE);
StyleConstants. setFontFamily(S ansSerifFontSty le, "SansSerif" );
Style SansSerifRegula rStyle =
textPane.addSty le("regular", SansSerifFontSt yle);
}
[/code]
(the actual code also had an italic style, etc.)
So, I changed it to
[code=java]
protected void setStyles(JText Pane textPane)
{
//Serif Font Style
Style SansSerifFontSt yle =
StyleContext.ge tDefaultStyleCo ntext().getStyl e
(StyleContext.D EFAULT_STYLE);
StyleConstants. setFontFamily(S ansSerifFontSty le, "SansSerif" );
Style SansSerifRegula rStyle =
textPane.addSty le("SansSerif-regular", SansSerifFontSt yle);
//Comic Font Style
Style comicFontStyle =
StyleContext.ge tDefaultStyleCo ntext().getStyl e
(StyleContext.D EFAULT_STYLE);
StyleConstants. setFontFamily(c omicFontStyle, "Comic Sans MS");
Style comicRegularSty le =
textPane.addSty le("Comic-regular", comicFontStyle) ;
}
[/code]
Then in my code I just prefixed the Document style name with Comic or SansSerif. Initially everything should have been SansSerif, but is was Comic. Looking at the documentation for the methods that I used, it looks like I probably just gave the same object two different names, but I'm a little unclear how to produce two different objects based on the DefaultStyleCon text. TIA --Sam
We had a program where we used a bunch of styles in a Document in a JTextPane. Everything worked fine until they wanted us to make a modification to use two different fonts. The original code that they provided was something like:
[code=java]
protected void setStyles(JText Pane textPane)
{
Style SansSerifFontSt yle =
StyleContext.ge tDefaultStyleCo ntext().getStyl e
(StyleContext.D EFAULT_STYLE);
StyleConstants. setFontFamily(S ansSerifFontSty le, "SansSerif" );
Style SansSerifRegula rStyle =
textPane.addSty le("regular", SansSerifFontSt yle);
}
[/code]
(the actual code also had an italic style, etc.)
So, I changed it to
[code=java]
protected void setStyles(JText Pane textPane)
{
//Serif Font Style
Style SansSerifFontSt yle =
StyleContext.ge tDefaultStyleCo ntext().getStyl e
(StyleContext.D EFAULT_STYLE);
StyleConstants. setFontFamily(S ansSerifFontSty le, "SansSerif" );
Style SansSerifRegula rStyle =
textPane.addSty le("SansSerif-regular", SansSerifFontSt yle);
//Comic Font Style
Style comicFontStyle =
StyleContext.ge tDefaultStyleCo ntext().getStyl e
(StyleContext.D EFAULT_STYLE);
StyleConstants. setFontFamily(c omicFontStyle, "Comic Sans MS");
Style comicRegularSty le =
textPane.addSty le("Comic-regular", comicFontStyle) ;
}
[/code]
Then in my code I just prefixed the Document style name with Comic or SansSerif. Initially everything should have been SansSerif, but is was Comic. Looking at the documentation for the methods that I used, it looks like I probably just gave the same object two different names, but I'm a little unclear how to produce two different objects based on the DefaultStyleCon text. TIA --Sam
Comment