2012-03-26 63 views
1

什么是改变与海玻璃JFrame的背景看,感觉有道,至今我都尝试:变化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(); 
       } 
      } 
     }); 
    }  

}

+0

负载L&F通过UIManager的。例如:http://stackoverflow.com/questions/9541045/how-to-set-jframe-look-and-feel之后,做任何你想要的,即改变其背景 – 2012-03-26 02:30:33

+0

一些L&F可能需要你改变一些UI通过调用setProperty()或其他东西。您可能需要查看其文档。也有L&F与一个“越野车”的实施,不允许你改变你想要的东西!如果发生这种情况,您可能需要重写其paintComponent()以使用其默认的UI组件绘画行为并应用新的组件绘画行为。 – 2012-03-26 02:48:18

回答