gpt4 book ai didi

java - JInternalFrame 在 Netbeans 7.1.2 中不使用 JFrame L&F

转载 作者:行者123 更新时间:2023-12-02 07:25:24 24 4
gpt4 key购买 nike

我正在使用 Netbeans 创建一个 MDI 应用程序,在外观设置为 Nimbus 的情况下,一切都按预期运行良好。

每当我运行应用程序时,JFrame 及其工具栏都会使用指定的 L&F (Nimbus),但内部框架使用跨平台(Metal)L&F,使应用程序看起来很破旧。

我希望内部框架使用与 JFrame 相同的 L&F。请问我该如何解决这个问题?

我尝试调用 JFrame.setdefaultlookandfeeldecorated(true)SwingUtilities.updatecomponenttreeui(frame) 但它们没有解决问题。

最佳答案

Anytime I run the application, the JFrame and its toolbars use the specified L&F (Nimbus) but the Internal Frames use the cross platform (Metal) L&F making the application look shabby.

enter image description here

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();
}
});
}
}

关于java - JInternalFrame 在 Netbeans 7.1.2 中不使用 JFrame L&F,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13642099/

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