gpt4 book ai didi

java - Ubuntu 中的 LookAndFeel 没有改变

转载 作者:行者123 更新时间:2023-12-01 16:41:06 25 4
gpt4 key购买 nike

有人知道为什么下面的代码中的 laf 没有改变吗? (在 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");
}

}

最佳答案

调用 UIManager.setLookAndFeel(lafClassName) 后,调用 SwingUtilities.updateComponentTreeUI(cb.getParent)。在更完整的应用程序中,您必须在每个顶级容器上调用它。由于 laf 之间的组件大小不同,您还应该在容器上调用 pack()

关于java - Ubuntu 中的 LookAndFeel 没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2655929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com