【发布时间】:2015-10-18 14:32:04
【问题描述】:
假设我有 2 个 JFrame。将 JFrame 设置为可见后,如果不先将可见性设置为隐藏和正常,您似乎无法更改 LAF。这意味着闪烁,JFrame 跳到顶部。
否则,你会得到这个:
(Metal 和 Ubuntu 系统 LAF 之间的某种混合)
另外,重绘似乎也无济于事。
现在,假设第一个 JFrame 是使用 Metal LAF 制作的。显示后,LAF 更改为系统 LAF。然后出现第二个。现在,第一个受到这个有趣的事情的影响。第二个没问题。为什么会这样?这是我的代码:
public static void main(String[] args) throws ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException {
JFrame first = new JFrame("First");
first.add(new JButton("Click me, I look funny"));
first.setPreferredSize(new Dimension(100, 100));
first.pack();
first.setVisible(true);
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
first.repaint();
JFrame second = new JFrame("Second");
second.add(new JButton("Click"));
second.setPreferredSize(new Dimension(100, 100));
second.pack();
second.setVisible(true);
second.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
那么我怎样才能让新的 LAF 只影响 1 个 JFrame?
或者LAF是全局的,不能只应用于1个JFrame?
【问题讨论】:
-
“假设我有 2 个 JFrame。” 见 The Use of Multiple JFrames, Good/Bad Practice?
标签: java swing look-and-feel uimanager