জাভা সুইং আমাদেরকে লুক অ্যান্ড ফিল(L&F) পরিবর্তন করে GUI কাস্টমাইজ করতে দেয় . চেহারা উপাদানগুলির সাধারণ চেহারা সংজ্ঞায়িত করে এবং অনুভূতি তাদের আচরণকে সংজ্ঞায়িত করে। L&Fs হল LookAndFeel -এর সাবক্লাস ক্লাস এবং প্রতিটি L&F এর সম্পূর্ণ যোগ্য শ্রেণীর নাম দ্বারা চিহ্নিত করা হয় . ডিফল্টরূপে, L&F Swing L&F ( মেটাল L&F) এ সেট করা আছে
L&F প্রোগ্রামগতভাবে সেট করতে, আমরা পদ্ধতিটিকে কল করতে পারি setLookAndFeel () UIManager -এর ক্লাস SetLookAndFeel-এ কলটি যেকোন জাভা সুইং ক্লাস ইনস্ট্যান্টিশিয়েট করার আগে অবশ্যই করা উচিত, অন্যথায়, ডিফল্ট সুইং 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();
}
} আউটপুট


