test.java

来自「swing 教程,与大家分享一下,哈哈,希望大家多多指教」· Java 代码 · 共 40 行

JAVA
40
字号
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;
import javax.swing.plaf.*;

public class Test extends JApplet {
	public void init() {
		Container contentPane = getContentPane();

		contentPane.setLayout(new FlowLayout());

		setMetalTheme(new ExperimentalTheme());

		contentPane.add(new JButton("button"));
		contentPane.add(new JCheckBox("check me"));
	}
	private void setMetalTheme(MetalTheme theme) {
		MetalLookAndFeel.setCurrentTheme(new ExperimentalTheme());

		// Metal Look and Feel must be (re)loaded for the
		// new theme to take effect ...

		try {
			UIManager.setLookAndFeel(
				"javax.swing.plaf.metal.MetalLookAndFeel");
		}
		catch(IllegalAccessException e1) {}
		catch(UnsupportedLookAndFeelException e2) {}
		catch(InstantiationException e3) {}
		catch(ClassNotFoundException e4) {}
	}
}
class ExperimentalTheme extends DefaultMetalTheme {
    public FontUIResource getControlTextFont() { 
		return new FontUIResource("SanSerif", 
							      Font.BOLD + Font.ITALIC, 24);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?