• Post Reply Bookmark Topic Watch Topic
  • New Topic

I can change fonts only once in the runtime

 
Ahmet Aksoy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a multi-language application.
Sometimes I need fonts to be changed while working.
I use JFontChooser in order to select a new font, then call the changeFonts(sf) method.
In the first call of changeFonts(sf) everything works as expected. However, when I call the same method with a different sf parameter for a second, or more calls nothing happens.
What might be the problem?
Ahmet Aksoy

/** AnaPanel.java **/
...
changeFonts(sf);
...
void changeFonts(Font sf){
UIManager.put("Button.font",sf);
UIManager.put("ToggleButton.font",sf);
UIManager.put("RadioButton.font",sf);
UIManager.put("CheckBox.font",sf);
UIManager.put("ColorChooser.font",sf);
UIManager.put("ToggleButton.font",sf);
UIManager.put("ComboBox.font",sf);
UIManager.put("ComboBoxItem.font",sf);
UIManager.put("InternalFrame.titleFont",sf);
UIManager.put("Label.font",sf);
UIManager.put("List.font",sf);
UIManager.put("MenuBar.font",sf);
UIManager.put("Menu.font",sf);
UIManager.put("MenuItem.font",sf);
UIManager.put("RadioButtonMenuItem.font",sf);
UIManager.put("CheckBoxMenuItem.font",sf);
UIManager.put("PopupMenu.font",sf);
UIManager.put("OptionPane.font",sf);
UIManager.put("Panel.font",sf);
UIManager.put("ProgressBar.font",sf);
UIManager.put("ScrollPane.font",sf);
UIManager.put("Viewport",sf);
UIManager.put("TabbedPane.font",sf);
UIManager.put("TableHeader.font",sf);
UIManager.put("TextField.font",sf);
UIManager.put("PasswordFiled.font",sf);
UIManager.put("TextArea.font",sf);
UIManager.put("TextPane.font",sf);
UIManager.put("EditorPane.font",sf);
UIManager.put("TitledBorder.font",sf);
UIManager.put("ToolBar.font",sf);
UIManager.put("ToolTip.font",sf);
UIManager.put("Tree.font",sf);

config.applyLookAndFeel(config.LOOK_AND_FEEL);
}
...

/** config.java **/
...
public void applyLookAndFeel(String name){
try {
UIManager.setLookAndFeel(name);
Frame frames[];

frames= Frame.getFrames();
SwingUtilities.updateComponentTreeUI(frames[0]);
frames[0].pack();
frames[0].repaint();

if(LOOK_AND_FEEL.equals(name)==false)LOOK_AND_FEEL=name;
}catch (Exception e) {

System.out.println("Error: "+e.toString());
}
}
...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> What might be the problem?

you are changing the value to a font, instead of to a FontUIResource

try this
 
Ahmet Aksoy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,
Many thanks for your explanatory answer, and the neat sample code.
My problem is solved.
Ahmet Aksoy
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!