我有一个java applet,唯一能正常工作的外观是原生的mac。我想把字体做大一点,并尝试使用标准的UIManager方法
UIManager.put("Label.font",新字体(“Label.font”,Font.PLAIN,18));
这不会产生任何变化。当然,它不会抛出异常。
有没有人知道原生mac的外观是否忽略了这些?
我知道有一些特定的方法可以让mac上的控件变得不同大小,但这些方法似乎只会让它们变小。您不能使控件比常规控件更大。
发布于 2010-05-24 04:13:49
它似乎可以在安装了L&F的Mac OS X上工作。
附录:如果您试图在启动后更改设置,请参阅下的。
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"));
}
}发布于 2010-05-24 06:55:56
updateComponentTreeUI(...)方法(由垃圾神提供的在启动后更改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);
}
}https://stackoverflow.com/questions/2892721
复制相似问题