2010-05-23 7 views
1

나는 Java 애플릿을 가지고 있으며, 모양과 느낌이 제대로 작동한다는 것은 기본 Mac 것입니다. 나는 글꼴을 약간 더 크게 만들고 표준 UIManager 메서드를 사용하여 시도했다.Java Mac OSX 기본 모양과 느낌이 UIManager 글꼴 변경을 존중합니까?

UIManager.put ("Label.font", new Font ("Georgia", Font.PLAIN, 18)));

이렇게 변경되지 않습니다. 물론 예외는 발생시키지 않습니다.

네이티브 맥 모양과 느낌이 이것을 무시하는지 아는 사람 있습니까?

저는 Mac에서 다양한 크기의 컨트롤을 만들 수있는 구체적인 방법이 있지만 이러한 것들만 작게 만듭니다. 컨트롤을 일반보다 크게 만들 수는 없습니다.

답변

1

이 설치된 L & F.

부록으로 맥 OS X에서 작동하도록 나타납니다 당신이 시작 후 설정을 변경하려는 경우, Changing the Look and Feel After Startup에서 How to Set the Look and Feel를 참조하십시오.

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

글꼴 대신 FontUIResource를 사용하는 것이 더 안전 할 수 있습니다. 제공된 데모를보십시오. – camickr

+0

JApplet을하고 있는데 init에서 설정 한 다음 변경하지 않았습니다. 그것은 Metal Look and Feel과 함께 작동하지만 필자는 metallookand 느낌의 아이 클래스를 생성하여이를 수행했습니다. 두 사람이 맥 네이티브 룩앤필을 가지고도이 기능이 작동한다고 생각하기 때문에 다시 시도 할 것입니다. 감사합니다. –

+0

위의 'JApplet'의 모든 L & F에 대해 @camickr에 의해 제기 된 점에 따라 작동합니다. – trashgod

1

(trashgod에서 제공하는 변경 LAF 시작 후 링크 참조)를 updateComponentTreeUI (...) 메소드 만 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); 
    } 
} 
+0

나는 그것을 몰랐다. 좋은 본보기! – trashgod