如何更改Swing GTK LookAndFeel中的默认字体大小? [英] How to change the default font size in the Swing GTK LookAndFeel?

查看:113
本文介绍了如何更改Swing GTK LookAndFeel中的默认字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Swing GTK LaF中更改默认字体大小?

GTK LaF似乎假设为72dpi,所以所有字体只有3 /当使用96dpi屏幕时,它们应该是4的大小。有关详细信息,请参阅此 Fedora bug 。我希望在此期间找到解决方法,同时等待修复。



我已经尝试通过重置字体大小, UIDefaults ,建议 here ,但是(同样在那里指出的)GTK LaF似乎忽略了这一点。



我可以构建一个widget工厂,该工厂还将设置所需的字体大小来创建所有Swing小部件,但这将是大规模入侵的,所以如果有任何其他方法,我想避免该路线。



编辑:以下内容无效:

  public class GTKLaF扩展com.sun.java.swing.plaf.gtk.GTKLookAndFeel {
@Override
public UIDefaults getDefaults(){
final float scale = 3f;

final UIDefaults defaults = super.getDefaults();

最终地图< Object,Object> changes = new HashMap< Object,Object>(); (Map.Entry< Object,Object> e:defaults.entrySet()){
final Object key = e.getKey();


final Object val = e.getValue();

if(val instanceof FontUIResource){
final FontUIResource ores =(FontUIResource)val;
final FontUIResource nres =
new FontUIResource(ores.deriveFont(ores.getSize2D()* scale));
changes.put(key,nres);
System.out.println(key +=+ nres);
}
else if(val instanceof Font){
final Font ofont =(Font)val;
final Font nfont = ofont.deriveFont(ofont.getSize2D()* scale);
changes.put(key,nfont);
System.out.println(key +=+ nfont);
}
}

defaults.putAll(changes);

返回默认值;




$ b你可能认为这会打印至少一打键值对,但它只打印一个:TitledBorder.font。显然其他字体属性不是由GTLLookAndFeel提供的,而是来自其他地方!

解决方案

似乎没有办法设置默认字体大小。然而,这个问题中引用的bug现在已经被修复了,所以现在需要这样做了。


Is there a way to change the default font size in the Swing GTK LaF?

The GTK LaF seems to assume 72dpi, so all the fonts are only 3/4 of the size they should be when using a 96dpi screen. See this Fedora bug for details. I'd like to find a workaround in the meantime, while I wait for the fix.

I've already tried resetting the font size via UIDefaults, as recommended here, for example, but (as also noted there) the GTK LaF appears to ignore this.

I could build a widget factory that would also set the desired font size for creating all of my Swing widgets, but that's going to be massively invasive, so I'd like to avoid that route if there's any other way.

Edit: The following doesn't work:

public class GTKLaF extends com.sun.java.swing.plaf.gtk.GTKLookAndFeel {
  @Override
  public UIDefaults getDefaults() {
    final float scale = 3f;

    final UIDefaults defaults = super.getDefaults(); 

    final Map<Object,Object> changes = new HashMap<Object,Object>();

    for (Map.Entry<Object,Object> e : defaults.entrySet()) {
      final Object key = e.getKey();
      final Object val = e.getValue();

      if (val instanceof FontUIResource) {
        final FontUIResource ores = (FontUIResource) val;
        final FontUIResource nres =
          new FontUIResource(ores.deriveFont(ores.getSize2D()*scale));
        changes.put(key, nres);
        System.out.println(key + " = " + nres);
      } 
      else if (val instanceof Font) {
        final Font ofont = (Font) val;
        final Font nfont = ofont.deriveFont(ofont.getSize2D()*scale);
        changes.put(key, nfont);
        System.out.println(key + " = " + nfont);
      }
    }

    defaults.putAll(changes);

    return defaults;
  }
}

You might think this would print at least a dozen key-value pairs, but it prints only one: TitledBorder.font. Apparently the other font properties are not supplied by the GTLLookAndFeel, but come from someplace else!

解决方案

There appears to be no way to set the default font size. However, the bug referenced in the question has since been fixed, so the need to do this is now moot.

这篇关于如何更改Swing GTK LookAndFeel中的默认字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆