swing
룩앤필 (look and feel) 사용
수색…
시스템 L & F 사용
스윙은 네이티브 L & F를 상당 부분 지원합니다.
특정 L & F 등급을 요구하지 않고도 언제든지 쉽게 설치할 수 있습니다.
public class SystemLookAndFeel { public static void main ( final String[] args ) { // L&F installation should be performed within EDT (Event Dispatch Thread) // This is important to avoid any UI issues, exceptions or even deadlocks SwingUtilities.invokeLater ( new Runnable () { @Override public void run () { // Process of L&F installation might throw multiple exceptions // It is always up to you whether to handle or ignore them // In most common cases you would never encounter any of those try { // Installing native L&F as a current application L&F // We do not know what exactly L&F class is, it is provided by the UIManager UIManager.setLookAndFeel ( UIManager.getSystemLookAndFeelClassName () ); } catch ( final ClassNotFoundException e ) { // L&F class was not found e.printStackTrace (); } catch ( final InstantiationException e ) { // Exception while instantiating L&F class e.printStackTrace (); } catch ( final IllegalAccessException e ) { // Class or initializer isn't accessible e.printStackTrace (); } catch ( final UnsupportedLookAndFeelException e ) { // L&F is not supported on the current system e.printStackTrace (); } // Now we can create some natively-looking UI // This is just a small sample frame with a single button on it final JFrame frame = new JFrame (); final JPanel content = new JPanel ( new FlowLayout () ); content.setBorder ( BorderFactory.createEmptyBorder ( 50, 50, 50, 50 ) ); content.add ( new JButton ( "Native-looking button" ) ); frame.setContentPane ( content ); frame.setDefaultCloseOperation ( WindowConstants.EXIT_ON_CLOSE ); frame.pack (); frame.setLocationRelativeTo ( null ); frame.setVisible ( true ); } } ); } }
JDK가 지원하는 기본 L & F입니다 (OS -> L & F).
OS | L & F 이름 | L & F 강좌 |
---|---|---|
Solaris, GTK +가있는 Linux | GTK + | com.sun.java.swing.plaf.gtk.GTKLookAndFeel |
기타 Solaris, Linux | 주제 | com.sun.java.swing.plaf.motif.MotifLookAndFeel |
클래식 윈도우 | Windows | com.sun.java.swing.plaf.windows.WindowsLookAndFeel |
윈도우 XP | 윈도우 XP | com.sun.java.swing.plaf.windows.WindowsLookAndFeel |
Windows Vista | Windows Vista | com.sun.java.swing.plaf.windows.WindowsLookAndFeel |
매킨토시 | 매킨토시 | com.apple.laf.AquaLookAndFeel * |
IBM UNIX | IBM | javax.swing.plaf.synth.SynthLookAndFeel * |
HP UX | HP | javax.swing.plaf.synth.SynthLookAndFeel * |
*이 L & F는 시스템 공급 업체가 제공하며 실제 L & F 클래스 이름은 다를 수 있습니다.
커스텀 L & F 사용하기
public class CustomLookAndFeel { public static void main ( final String[] args ) { // L&F installation should be performed within EDT (Event Dispatch Thread) // This is important to avoid any UI issues, exceptions or even deadlocks SwingUtilities.invokeLater ( new Runnable () { @Override public void run () { // Process of L&F installation might throw multiple exceptions // It is always up to you whether to handle or ignore them // In most common cases you would never encounter any of those try { // Installing custom L&F as a current application L&F UIManager.setLookAndFeel ( "javax.swing.plaf.metal.MetalLookAndFeel" ); } catch ( final ClassNotFoundException e ) { // L&F class was not found e.printStackTrace (); } catch ( final InstantiationException e ) { // Exception while instantiating L&F class e.printStackTrace (); } catch ( final IllegalAccessException e ) { // Class or initializer isn't accessible e.printStackTrace (); } catch ( final UnsupportedLookAndFeelException e ) { // L&F is not supported on the current system e.printStackTrace (); } // Now we can create some pretty-looking UI // This is just a small sample frame with a single button on it final JFrame frame = new JFrame (); final JPanel content = new JPanel ( new FlowLayout () ); content.setBorder ( BorderFactory.createEmptyBorder ( 50, 50, 50, 50 ) ); content.add ( new JButton ( "Metal button" ) ); frame.setContentPane ( content ); frame.setDefaultCloseOperation ( WindowConstants.EXIT_ON_CLOSE ); frame.pack (); frame.setLocationRelativeTo ( null ); frame.setVisible ( true ); } } ); } }
여기서 주제로 사용 가능한 Swing L & F의 목록을 찾을 수 있습니다 : Java Look and Feel (L & F)
L & F 중 일부는이 시점에서 구식이 될 수 있음을 명심하십시오.
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow