Label에 대한 Font를 나눔고딕(NanumGothic)으로 설정.

UIManager.put("Label.font", new Font("NanumGothic", Font.PLAIN, 12));


다른 Component의 Font를 설정하고 싶을때에는 해당 Key 값을 변경하면 되겠다.

Swing Component의 Font Key 값은 아래와 같다.


Swing Platform FontUIResources.

Key : OptionPane.buttonFont

Key : List.font

Key : TableHeader.font

Key : Panel.font

Key : TextArea.font

Key : ToggleButton.font

Key : ComboBox.font

Key : ScrollPane.font

Key : Spinner.font

Key : RadioButtonMenuItem.font

Key : Slider.font

Key : EditorPane.font

Key : OptionPane.font

Key : ToolBar.font

Key : Tree.font

Key : CheckBoxMenuItem.font

Key : FileChooser.listFont

Key : Table.font

Key : MenuBar.font

Key : PopupMenu.font

Key : Label.font

Key : MenuItem.font

Key : MenuItem.acceleratorFont

Key : TextField.font

Key : TextPane.font

Key : CheckBox.font

Key : ProgressBar.font

Key : FormattedTextField.font

Key : CheckBoxMenuItem.acceleratorFont

Key : Menu.acceleratorFont

Key : ColorChooser.font

Key : Menu.font

Key : PasswordField.font

Key : InternalFrame.titleFont

Key : OptionPane.messageFont

Key : RadioButtonMenuItem.acceleratorFont

Key : Viewport.font

Key : TabbedPane.font

Key : RadioButton.font

Key : ToolTip.font

Key : Button.font



해당 Swing Component 전체 Font를 나눔고딕(NanumGothic)으로 설정.

setUIFont(new javax.swing.plaf.FontUIResource("NanumGothic", java.awt.Font.PLAIN, 12));
	
public static void setUIFont(javax.swing.plaf.FontUIResource f) {
	java.util.Enumeration keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if (value instanceof javax.swing.plaf.FontUIResource) {
        	 UIManager.put(key, f);
        }
    }
}



Swing Application을 실행하기 전에 적용하고 실행하면 되겠다.


Writing...



블로그 이미지

행복그리고..

,
     public static double getJavaVersion() {
		String javaVersion = System.getProperty("java.version");
		double version = Double.parseDouble(javaVersion.substring(0, 3));
		return version;
	}
	

	public static void setLookAndFeel(String lookAndFeelName) {
		if (getJavaVersion() > 1.5) {
			try {
				LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels();
			    for (LookAndFeelInfo info : plafs) {
			    	if (info.getName().equals(lookAndFeelName)) {
			    		UIManager.setLookAndFeel(info.getClassName());
			    	}
			    }
			} catch (Exception pe) {
				try {
					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
				} catch (Exception ce) {
					ce.printStackTrace();
				}
			}
		}
		
	}
	
	public static void setLookAndFeel(String lookAndFeelName, JComponent component) {
		if (getJavaVersion() > 1.5) {
			try {
				LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels();
			    for (LookAndFeelInfo info : plafs) {
			    	if (info.getName().equals(lookAndFeelName)) {
			    		UIManager.setLookAndFeel(info.getClassName());
			    		SwingUtilities.updateComponentTreeUI(component);
			    		break;
			    	}
			    }
			} catch (Exception pe) {
				try {
					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
				} catch (Exception ce) {
					ce.printStackTrace();
				}
			}
		}
	}

Swing Look And Feel JRE(Java Runtime Environment) 1.6 이상 지원이 된다.


기본적으로 JRE 1.6 이상 지원이 되는 Look And Feel에는

Metal, Nimbus, CDE/Motif, Windows, Windows Classic


Writing....

블로그 이미지

행복그리고..

,


import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

class MyFrame extends JFrame implements ActionListener {
	⁄**
	 * 
	 *⁄
	private static final long serialVersionUID = -9026464211228409376L;
	
	private JButton setSizeButton = new JButton("setSize");
	private JButton setPreferredSizeButton = new JButton("setPreferredSize");
	private JButton repaintButton = new JButton("Repaint");
	public MyFrame(String title) {
		super(title);
		setSize(400, 200);
		
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frameSize = getSize();
		int x = (int) (screenSize.getWidth() - frameSize.getWidth()) ⁄ 2;
		int y = (int) (screenSize.getHeight() - frameSize.getHeight()) ⁄ 2;
		this.setLocation(x, y);
		
		JPanel panel = new JPanel();
		setSizeButton.addActionListener(this);
		setPreferredSizeButton.addActionListener(this);
		repaintButton.addActionListener(this);
		panel.add(setSizeButton);
		panel.add(setPreferredSizeButton);
		panel.add(repaintButton);
		addComponentListener(new ComponentAdapter() {
			@Override
			public void componentResized(ComponentEvent e) {
				super.componentResized(e);
				System.out.println("componenet Resized(ComponentEvent e)");
			}
		});
		this.add(panel);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	}
	
	@Override
	public void paint(Graphics g) {
		super.paint(g);

		System.out.println("paint(Graphics g)");
		System.out.println("Frame getSize() : " + getSize());
		System.out.println("Frame getPreferredSize() : " + getPreferredSize());
		System.out.println();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		JButton actionButton = (JButton)e.getSource();
		Dimension thisSize = getSize();
		thisSize.setSize(thisSize.height, thisSize.width);
		if (actionButton == setSizeButton) {
			this.setSize(thisSize);
		} else if (actionButton == setPreferredSizeButton){
			this.setPreferredSize(thisSize);
		} else if (actionButton == repaintButton) {
			this.repaint();
		}
	}
}

코드를 실행해보면 결과와 같이 setSize 같은경우 해당 Frame을 다시 그리고, setPrefereedSize 같은 경우에는 그리지 않는다.


Writing...

'JAVA Platform > JAVA' 카테고리의 다른 글

[JAVA] - Swing Component Font 설정하기  (0) 2015.04.11
[JAVA] - Swing Look And Feel 적용하기  (0) 2015.04.01
[JAVA] - File 실행하기  (0) 2015.03.22
[JAVA] - JNDI Database Connection  (0) 2015.03.19
[JAVA] - DBMS JDBC Connection  (0) 2015.02.13
블로그 이미지

행복그리고..

,