1

我正在使用 Nimbus L&F 并尝试更改背景颜色。我用这个设置颜色:iFrame.getContentPane().setBackground(Color.BLACK);. 然而,它最终在顶部有一个小区域,带有默认颜色。甚至更糟。如果我重新调整 JInternalFrame 的大小,这个区域会将其颜色从深灰色变为浅灰色。我搜索了这个问题,至少我发现它必须是标题栏引起的问题。

JInternalFrame 的图片

有没有办法解决这个问题?这是一个已知的错误?谢谢你。

编辑:

一个小程序,它发生的地方。以下行导致问题:ret.put("defaultFont", new Font("Arial", Font.BOLD, 16));这是设置默认字体的错误方法吗?

package jInternalFrameTest;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.lang.reflect.InvocationTargetException;

import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLayeredPane;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;


public class JInternalFrameTest extends JFrame {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public JInternalFrameTest() {
        super("JInternalFrame Background Demo");
        int inset = 50;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset * 2);
        addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        createGUI();
    }

    private void createGUI() {
        MyInternalFrame frame = new MyInternalFrame();
        frame.setVisible(true);
        this.getLayeredPane().add(frame, JLayeredPane.DRAG_LAYER);
        try {
            frame.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

        try {
            SwingUtilities.invokeAndWait(new Runnable() {

                @Override
                public void run() {

                    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {

                        if ("Nimbus".equals(info.getName())) {

                            try {

                                UIManager.setLookAndFeel(new NimbusLookAndFeel(){

                                    /**
                                    * 
                                    */
                                    private static final long serialVersionUID = 1L;

                                    @Override
                                    public UIDefaults getDefaults() {
                                        UIDefaults ret = super.getDefaults();
                                        ret.put("defaultFont", new Font("Arial", Font.BOLD, 16));
                                        return ret;
                                    }
                                });

                            } catch (UnsupportedLookAndFeelException e) {
                                   e.printStackTrace();
                            }
                        }
                    }

                    new JInternalFrameTest().setVisible(true);

                }
            });

        } catch (InvocationTargetException | InterruptedException e) {
            e.printStackTrace();
        }
    }

    class MyInternalFrame extends JInternalFrame {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public MyInternalFrame() {
            super("IFrame", true, // resizable
                true, // closable
                true, // maximizable
                true);// iconifiable
            setSize(300, 300);
            getContentPane().setBackground(Color.BLACK);
                pack();
            }
    }
}
4

0 回答 0