Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Mac OSX本机外观是否尊重UIManager字体更改?_Java_Macos_Swing_Size_Fonts - Fatal编程技术网

Java Mac OSX本机外观是否尊重UIManager字体更改?

Java Mac OSX本机外观是否尊重UIManager字体更改?,java,macos,swing,size,fonts,Java,Macos,Swing,Size,Fonts,我有一个java小程序,唯一能正常工作的外观是本机的mac小程序。我想把字体放大一点,并尝试使用标准的UIManager方法 UIManager.put(“Label.font”,新字体(“Georgia”,font.PLAIN,18)) 这不会产生任何变化。当然,它不会抛出异常 有人知道本地mac的外观是否忽略了这些吗 我知道有一些特定的方法可以在mac上制作不同大小的控件,但这些方法似乎只会使控件变小。您不能使控件比常规控件大。它似乎可以在安装了L&F的Mac OS X上工作 附录:如果您试

我有一个java小程序,唯一能正常工作的外观是本机的mac小程序。我想把字体放大一点,并尝试使用标准的UIManager方法

UIManager.put(“Label.font”,新字体(“Georgia”,font.PLAIN,18))

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

有人知道本地mac的外观是否忽略了这些吗


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

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

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

updateComponentTreeUI(…)方法(由trashgod提供的在启动后更改LAF链接中引用)将仅在FontUIResource上工作,而不是字体。这仅在启动后需要多次更改字体时才相关

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);
    }
}

使用FontUIResource而不是字体可能更安全。请参阅提供的演示。我正在使用JApplet进行操作,并在init中进行设置,然后不进行更改。它与金属外观一起工作,但我通过创建一个金属外观的子类实现了这一点。因为有两个人认为即使是mac原生外观也可以使用,所以我会再试一次。thanksIt适用于上述
JApplet
中的所有L&F,受@camickr提出的观点的约束。我不知道这一点。好榜样!
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);
    }
}