Java 如何改变JDesktopPane的外观和感觉?

Java 如何改变JDesktopPane的外观和感觉?,java,swing,user-interface,look-and-feel,jdesktoppane,Java,Swing,User Interface,Look And Feel,Jdesktoppane,我将项目的LAF设置为系统默认的外观。现在我试图在我的一个面板中放置一个JDesktopPane,但我希望所有的内部框架都使用java默认LAF。有没有一种方法可以在不改变整个项目LAF的情况下改变它? import java.awt.BorderLayout; import javax.swing.JComponent; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInterna

我将项目的LAF设置为系统默认的外观。现在我试图在我的一个面板中放置一个JDesktopPane,但我希望所有的内部框架都使用java默认LAF。有没有一种方法可以在不改变整个项目LAF的情况下改变它?


import java.awt.BorderLayout;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.plaf.DesktopPaneUI;

public class AddingInternalFramestoaJDesktopPane {
  public static void main(final String[] args) throws Exception {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JDesktopPane desktop = new JDesktopPane();
    desktop.setUI(new DesktopPaneUI() {
    @Override
        public void installUI(JComponent c) {
            // TODO Auto-generated method stub
            try {
                UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
            } catch (Exception e) {
                e.printStackTrace();
            }
            super.installUI(c);
        }   
    });
    JInternalFrame internalFrame = new JInternalFrame("Can Do All", true, true, true, true);
    desktop.add(internalFrame);
    internalFrame.setBounds(25, 25, 200, 100);
    JLabel label = new JLabel(internalFrame.getTitle(), JLabel.CENTER);
    internalFrame.add(label, BorderLayout.CENTER);
    internalFrame.setVisible(true);
    frame.add(desktop, BorderLayout.CENTER);
    frame.setSize(500, 300);
    frame.setVisible(true);
  }
}
deks.setUI(新的DesktopPaneUI(){
@凌驾
public void installUI(JComponent c){
//TODO自动生成的方法存根
试一试{
setLookAndFeel(“com.sun.java.swing.plaf.motif.motif-lookandfeel”);
}捕获(例外e){
e、 printStackTrace();
}
super.installUI(c);
}
});

有了这个,一些文件需要包括

import javax.swing.JDesktopPane
import javax.swing.UIManager
导入javax.swing.plaf.DesktopPaneUI

它很重要


JDesktopPane deks=newjdesktoppane()

可能是:有人能给我一个答案吗。如何使用.setUI()方法?文档“更新组件树”的顶部提到了该方法。混合格子有很多怪癖(bug)。欢迎来到SO。请阅读这篇文章,提供一个高质量的答案。