首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Java Mac OSX原生外观是否支持UIManager字体更改?

Java Mac OSX原生外观是否支持UIManager字体更改?
EN

Stack Overflow用户
提问于 2010-05-24 01:35:46
回答 2查看 2.1K关注 0票数 1

我有一个java applet,唯一能正常工作的外观是原生的mac。我想把字体做大一点,并尝试使用标准的UIManager方法

UIManager.put("Label.font",新字体(“Label.font”,Font.PLAIN,18));

这不会产生任何变化。当然,它不会抛出异常。

有没有人知道原生mac的外观是否忽略了这些?

我知道有一些特定的方法可以让mac上的控件变得不同大小,但这些方法似乎只会让它们变小。您不能使控件比常规控件更大。

EN

回答 2

Stack Overflow用户

发布于 2010-05-24 04:13:49

它似乎可以在安装了L&F的Mac OS X上工作。

附录:如果您试图在启动后更改设置,请参阅下的。

代码语言:javascript
运行
复制
public final class Laf {

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                JFrame f = new JFrame();
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                UIManager.put("Label.font", new Font("Georgia", Font.PLAIN, 18));
                f.add(new JLabel("Test"));
                f.pack();
                f.setVisible(true);
            }
        });
    }
}

public final class LafApplet extends JApplet {

    @Override
    public void init() {
        UIManager.put("Label.font", new Font("Georgia", Font.PLAIN, 18));
        this.add(new JLabel("Test"));
    }
}
票数 1
EN

Stack Overflow用户

发布于 2010-05-24 06:55:56

updateComponentTreeUI(...)方法(由垃圾神提供的在启动后更改LAF链接中引用)只能在FontUIResource上工作,而不能在字体上工作。只有当您需要在启动后多次更改字体时,此选项才有意义。

代码语言:javascript
运行
复制
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.*;

public class ChangeFont extends JFrame
{
    private int size = 12;
    private JComponent component;

    public ChangeFont()
    {
        JTextArea textArea = new JTextArea();
        textArea.append( "updateComponentTreeUI will only work on a FontUIResource\n\n" );
        textArea.append( "1) click the FontUIResource button as many times as you want\n" );
        textArea.append( "2) after you click the Font button, neither button will work" );
        getContentPane().add(textArea, BorderLayout.NORTH);

        JButton west = new JButton( "FontUIResource" );
        west.addActionListener( new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                update( new FontUIResource("monospaced", Font.PLAIN, size) );
            }
        });
        getContentPane().add(west, BorderLayout.WEST );

        JButton east = new JButton( "Font" );
        east.addActionListener( new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                update( new Font("monospaced", Font.PLAIN, size) );
            }
        });
        getContentPane().add(east, BorderLayout.EAST );

        component = new JTable(5, 5);
        getContentPane().add(component, BorderLayout.SOUTH);
    }

    private void update(Font font)
    {
        UIManager.put("Table.font", font);
        UIManager.put("TextArea.font", font);
        SwingUtilities.updateComponentTreeUI( this );
        size += 2;
        pack();
    }

    public static void main(String[] args)
    {
        ChangeFont frame = new ChangeFont();
        frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
        frame.pack();
        frame.setLocationRelativeTo( null );
        frame.setVisible(true);
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2892721

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档