每当我运行应用程序时,JFrame 及其工具栏使用指定的 L&F (Nimbus),但内部框架使用跨平台 (Metal) L&F,使应用程序看起来很破旧。
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
public class TestInternalFrame {
public TestInternalFrame() {
final JInternalFrame internal = new JInternalFrame("test");
final JInternalFrame hidden = new JInternalFrame("test");
hidden.setBounds(1000, 1000, 1, 1);
hidden.setVisible(true);
internal.setVisible(true);
internal.setBounds(0, 0, 100, 100);
JDesktopPane pane = new JDesktopPane();
pane.add(internal);
pane.add(hidden);
pane.setPreferredSize(new Dimension(10000, 10000));
final JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(new JScrollPane(pane,
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
/*frame.getContentPane().add(new JButton(new AbstractAction("Show blocked dialog") {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showInternalMessageDialog(hidden, "Hi 2!");
}
});
JOptionPane.showInternalMessageDialog(internal, "Hi 1!");
}
}), BorderLayout.PAGE_END);*/
frame.setPreferredSize(new Dimension(400, 300));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
System.out.println(info.getName());
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
}
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
TestInternalFrame tif = new TestInternalFrame();
}
});
}
}