JAVA LookAndFeel Demo

스윙의 컴포넌트 스퇄이 달라지게 할 수 있당.

  1. UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
  2. SwingUtilities.updateComponentTreeUI(this);

    UIManager를 통해서 룩앤필 갈아끼우고
    SwingUtiliteis.update()를 통해서 UI를 업데이트시킨다. 
    이 모든게 프로그램 실행중에 이루어질수 있다는 사실! 차암 놀랍죠~잉.


LookNfeelTest.java




  1. import javax.swing.*;
  2. import javax.swing.tree.*;
  3. import java.awt.event.*;
  4. import java.awt.*;
  5.  
  6. public class LookNFeelTest extends JFrame implements ActionListener {
  7.    
  8.     JButton metal,motif,window;
  9.     JTree tree;
  10.     LookNFeelTest(){
  11.         super("LookNFeel Test");
  12.         DefaultMutableTreeNode root= new DefaultMutableTreeNode("컴퓨터 관련 기술");
  13.         DefaultMutableTreeNode java= new DefaultMutableTreeNode("Java");
  14.         DefaultMutableTreeNode c= new DefaultMutableTreeNode("C Language");
  15.         DefaultMutableTreeNode os= new DefaultMutableTreeNode("OS");
  16.         DefaultMutableTreeNode swing= new DefaultMutableTreeNode("Swing");
  17.         DefaultMutableTreeNode thread= new DefaultMutableTreeNode("Thead");
  18.         DefaultMutableTreeNode tuning= new DefaultMutableTreeNode("Tuning");
  19.        
  20.         java.add(swing);
  21.         c.add(thread);
  22.         os.add(tuning);
  23.        
  24.         root.add(java);
  25.         root.add(os);
  26.         root.add(c);
  27.        
  28.         tree = new JTree(root);
  29.         JScrollPane sp = new JScrollPane(tree);
  30.        
  31.         JPanel bottom = new JPanel();
  32.         metal = new JButton("JAVA");
  33.         metal.addActionListener(this);
  34.         motif = new JButton("MOTIF");
  35.         motif.addActionListener(this);
  36.         window = new JButton("WINDOW");
  37.         window.addActionListener(this);
  38.        
  39.         bottom.add(metal);
  40.         bottom.add(motif);
  41.         bottom.add(window);
  42.        
  43.         getContentPane().add(sp,"Center");
  44.         getContentPane().add(bottom,"South");
  45.        
  46.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  47.         setSize(300,200);
  48.         setVisible(true);
  49.        
  50.     }
  51.    
  52.     public void actionPerformed(ActionEvent e){
  53.         Object o = e.getSource();
  54.        
  55.         if(o==metal){
  56.             try{
  57.                 UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
  58.                 SwingUtilities.updateComponentTreeUI(this);
  59.             }catch(Exception ex1){
  60.                 ex1.printStackTrace();
  61.             }
  62.         }else if(o==motif){
  63.             try{
  64.                 UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
  65.                 SwingUtilities.updateComponentTreeUI(this);
  66.             }catch(Exception ex2){
  67.                 ex2.printStackTrace();
  68.             }
  69.         }else if(o==window){
  70.             try{
  71.                 UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel)");
  72.                 SwingUtilities.updateComponentTreeUI(this);
  73.             }catch(Exception ex3){
  74.                 ex3.printStackTrace();
  75.             }
  76.         }
  77.     }
  78.     public static void main(String[] args) {
  79.         new LookNFeelTest();
  80.     }
  81.  
  82. }



댓글

이 블로그의 인기 게시물

[Win32 API] WINAPI - 함수호출규약

JAVA Frame Icon setting

JAVA Spinner