السلام عليكــم ورحمـة الله وبركاتــه ،،
منذ النسخة السادسة تحديث 10 java6u10، يمكن استعمال look & feel جديد "Nimbus"، والكلاس الخاصة به هي
com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel


هناك ثلاثة طرق لاستعمال nimbus
أ.
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (InstantiationException e) {
} catch (ClassNotFoundException e) {
} catch (UnsupportedLookAndFeelException e) {
} catch (IllegalAccessException e) {}
try {ولكني لا أنصح بهذه الطريقة لأن الحزمة التي تحتوي على الكلاس NimbusLookAndFeel سيتغير إسمها في النسخة السابعة من الjdk
ب.
تحديد الlook & feel عند تنفيذ البرنامج لا داخل الكود
java -Dswing.defaultlaf=com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel MyProgram
ج.
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (UnsupportedLookAndFeelException e) {
// handle exception
} catch (ClassNotFoundException e) {
// handle exception
} catch (InstantiationException e) {
// handle exception
} catch (IllegalAccessException e) {
// handle exception
}
try {هذه هي أفضل طريقة، لأنها أولا ترى إذا كان nimbus متوفرا، وإذا كان كذلك تقوم بتطبيقه
وهذا مثال بسيط يستعمل nimbus
import javax.swing.UIManager.LookAndFeelInfo;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.BorderLayout;
public class NimbusFrame extends JFrame {
public NimbusFrame() {
JMenuBar menuBar = new JMenuBar();
JMenu mnFile = new JMenu("File");
JMenuItem itmExit = new JMenuItem("Exit");
itmExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
});
mnFile.add(itmExit);
menuBar.add(mnFile);
JProgressBar progress = new JProgressBar();
progress.setIndeterminate(true);
JButton btn = new JButton("Say hello");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae)
{
JOptionPane.showMessageDialog(NimbusFrame.this, "Hello Nimbus");
}
});
this.setJMenuBar(menuBar);
this.setSize(400, 300);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().add(btn, BorderLayout.NORTH);
this.getContentPane().add(progress, BorderLayout.SOUTH);
this.setVisible(true);
}
public static void main(String[] args) {
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
new NimbusFrame();
}
}
import javax.swing.*;
