জাভা সুইং আমাদের GUI কাস্টমাইজ করার অনুমতি দেয় লুক অ্যান্ড ফিল (L&F) পরিবর্তন করে। লুক নির্ধারণ করে কম্পোনেন্টের সাধারণ চেহারা এবং ফিল নির্ধারণ করে তাদের বিহেভিয়র। L&F-গুলো LookAndFeel ক্লাসের সাবক্লাস এবং প্রতিটি L&F এর ফুলি কোয়ালিফাইড ক্লাস নাম দিয়ে আইডেন্টিফাই করা হয়। ডিফল্টভাবে, L&F সেট থাকে Swing L&F (Metal L&F)।
প্রোগ্রামেটিক্যালি L&F সেট করতে, আমরা UIManager ক্লাসের setLookAndFeel() মেথড কল করতে পারি। setLookAndFeel কলটি যেকোনো জাভা সুইং ক্লাস ইনস্ট্যানশিয়েট করার আগে করতে হবে, অন্যথায় ডিফল্ট Swing L&F লোড হয়ে যাবে।
সিনট্যাক্স
public static void setLookAndFeel(LookAndFeel newLookAndFeel) throws UnsupportedLookAndFeelException
উদাহরণ
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class LookAndFeelTest extends JFrame implements ActionListener { private JRadioButton windows, metal, motif, ; private ButtonGroup bg; public LookAndFeelTest() { setTitle("Look And Feels"); windows = new JRadioButton("Windows"); windows.addActionListener(this); metal = new JRadioButton("Metal"); metal.addActionListener(this); motif = new JRadioButton("Motif"); motif.addActionListener(this); bg = new ButtonGroup(); bg.add(windows); bg.add(metal); bg.add(motif); setLayout(new FlowLayout()); add(windows); add(metal); add(motif); setSize(400, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); } @Override public void actionPerformed(ActionEvent ae) { String LAF; if(ae.getSource() == windows) LAF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; else if(ae.getSource() == metal) LAF = "javax.swing.plaf.metal.MetalLookAndFeel"; else LAF = "com.sun.java.swing.plaf.motif.MotifLookAndFeel"; try { UIManager.setLookAndFeel(LAF); SwingUtilities.updateComponentTreeUI(this); } catch (Exception e) { System.out.println("Error setting the LAF..." + e); } } public static void main(String args[]) { new LookAndFeelTest(); } }
আউটপুট


