http://blog.livedoor.jp/lalha_java/archives/50747986.html !サンプル1 MyLookAndFeel.java {{code Java, import javax.swing.plaf.basic.BasicLookAndFeel; public class MyLookAndFeel extends BasicLookAndFeel { public String getDescription() { return "This is My Look & Feel."; } public String getID() { return "MyLookAndFeel"; } public String getName() { return "My Look & Feel"; } public boolean isNativeLookAndFeel() { return false; } public boolean isSupportedLookAndFeel() { return true; } } }} LookAndFeelTest.java {{code Java, import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.UIManager; public class LookAndFeelTest { public static void main(String[] args) { try { UIManager.setLookAndFeel(new MyLookAndFeel()); } catch (Exception e) { } JFrame frame = new JFrame("Look & Feel サンプル"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JTextField textField = new JTextField(10); JButton button = new JButton("検索"); frame.getContentPane().add(panel); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.add(Box.createHorizontalGlue()); panel.add(textField); panel.add(Box.createHorizontalStrut(5)); panel.add(button); panel.add(Box.createHorizontalGlue()); frame.pack(); frame.setVisible(true); } } }} !サンプル2 MyTextFieldUI.java {{code Java, import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTextFieldUI; public class MyTextFieldUI extends BasicTextFieldUI { private static final Color GRADATION_START = new Color(255, 255, 255, 0); private static final Color GRADATION_END = new Color(0, 0, 0, 64); private final JComponent comp; public MyTextFieldUI(JComponent comp) { if (comp == null) { throw new IllegalArgumentException( "comp should not be null."); } this.comp = comp; } public static ComponentUI createUI(JComponent c) { return new MyTextFieldUI(c); } protected void paintBackground(Graphics g) { super.paintBackground(g); Dimension size = comp.getSize(); MyLookAndFeelUtil.gradationFill( GRADATION_START, GRADATION_END, 0, 0, size.width, size.height, g); } } }} MyButtonUI.java {{code Java, import java.awt.Color; import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicButtonUI; public class MyButtonUI extends BasicButtonUI { private static final Color GRADATION_START = new Color(255, 255, 255, 0); private static final Color GRADATION_END = new Color(0, 0, 0, 64); public static ComponentUI createUI(JComponent c) { return new MyButtonUI(); } public void paint(Graphics g, JComponent c) { super.paint(g, c); MyLookAndFeelUtil.gradationFill( GRADATION_START, GRADATION_END, 0, 0, c.getWidth(), c.getHeight(), g); } } }} MyLookAndFeelUtil.java {{code Java, import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Rectangle; public class MyLookAndFeelUtil { public static void gradationFill( Color c1, Color c2, int x, int y, int width, int height, Graphics g) { Paint p = new GradientPaint( (float)x, (float)y, c1, (float)x, (float)(y + height), c2); fill(p, x, y, width, height, g); } public static void fill( Paint p, int x, int y, int width, int height, Graphics g) { Graphics2D g2d = (Graphics2D)g; g2d.setPaint(p); g2d.fill(new Rectangle(x, y, width, height)); } } }} MyLookAndFeel.java {{code Java, import javax.swing.UIDefaults; import javax.swing.plaf.basic.BasicLookAndFeel; public class MyLookAndFeel extends BasicLookAndFeel { public String getDescription() { return "This is My Look & Feel."; } public String getID() { return "MyLookAndFeel"; } public String getName() { return "My Look & Feel"; } public boolean isNativeLookAndFeel() { return false; } public boolean isSupportedLookAndFeel() { return true; } public UIDefaults getDefaults() { UIDefaults uiDefaults = super.getDefaults(); uiDefaults.putDefaults(new Object[] { "ButtonUI", "MyButtonUI", "TextFieldUI", "MyTextFieldUI", }); return uiDefaults; } } }} {{category2 プログラミング言語,Java}}