任何人都知道爲什麼laf在下面的代碼中沒有改變? (在Ubuntu上運行)LookAndFeel在Ubuntu中沒有變化
import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
public class TEST extends JPanel {
public TEST() {
final LookAndFeelInfo[] lafArray = UIManager.getInstalledLookAndFeels();
String[] names = new String[lafArray.length];
for (int i = 0; i < names.length; i++) {
names[i] = lafArray[i].getName();
}
final JComboBox cb = new JComboBox(names);
cb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
try {
int index = cb.getSelectedIndex();
LookAndFeelInfo lafInfo = lafArray[index];
String lafClassName = lafInfo.getClassName();
System.out.println(lafClassName);
UIManager.setLookAndFeel(lafClassName);
} catch (Exception e) {
e.printStackTrace();
}
}
});
add(cb);
}
public static void main(String[] args) throws Exception {
System.out.println("start");
JDialog dialog = new JDialog(null, Dialog.ModalityType.APPLICATION_MODAL);
dialog.setContentPane(new TEST());
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
dialog.dispose();
System.out.println("end");
}
}
我想在運行時更改,就像SwingSet3那樣 – 2010-04-16 21:07:19
根據應用程序,看起來像是要求用戶重新啓動應用程序沒有其他選擇。傷心。 – 2010-04-19 13:35:54
@Tom:實際上,Java教程中的註釋指的是如果您沒有將L&F設置爲應用程序中的第一步,Java L&F可能會被初始化,即使這不是您想要的。這並不意味着你以後不能更改L&F。請參閱您鏈接到的頁面中的「更改啓動後的外觀」一節。 – Grodriguez 2010-09-22 12:20:52