【问题标题】:Change JFrame's background in Sea-Glass Look and Feel更改 Sea-Glass 外观中的 JFrame 背景
【发布时间】:2012-03-26 01:43:08
【问题描述】:

使用 Sea-Glass 外观更改为 JFrame 背景的正确方法是什么,到目前为止我都尝试了:

frame.getContentPane().setBackground(Color.blue);

JPanel x = new JPanel();
x.setBackground(Color.red);
frame.setContentPane(x);

但它没有任何效果:

import javax.swing.*;
import com.seaglasslookandfeel.*;
import java.awt.*;
import java.awt.Color.*; 
public class BORDER_TEST {
public static void main(String[] a){

        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {

                    UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
                    JFrame frame = new JFrame();
                    JPanel x = new JPanel();
                    x.setBackground(Color.red);
                    frame.setContentPane(x);

                    //frame.getContentPane().setBackground(Color.blue);
                    frame.setPreferredSize(new Dimension(900,350));
                    frame.setAlwaysOnTop(true);
                    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                    } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }    

}

【问题讨论】:

  • 在 main 方法中的任何代码之前通过 UIManager 加载 L&F。例如:stackoverflow.com/questions/9541045/… 之后,做任何你想做的事情,即改变它的背景
  • 一些 L&F 可能需要您通过调用 setProperty() 或其他方式更改一些 UI 属性。您可能需要查看其文档。还有一些 L&F 带有“错误”实现,不允许您更改为您想要的东西!如果发生这种情况,您可能需要重写其 paintComponent() 以使用其默认的 UI 组件绘制行为并应用新的组件绘制行为。

标签: java swing look-and-feel nimbus


【解决方案1】:

SeaglassLook and Feel是基于Nimbus,那么你必须接受它的内置主题或者设置Colors for Nimbus programatically

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    • 2015-11-16
    • 2012-01-05
    相关资源
    最近更新 更多