应用了Substance观感,皮肤为CremeSkin 时,我组件颜色不能正确显示。 设置黑色结果看到的是灰色。红色看到的是黑红。总之颜色不正常。原因我也大概知道,就是受到这个CremeColorScheme类里面设置的颜色影响。我想找到jpanel这个组件,让它不受皮肤颜色控制,但是找了很久,还是没有找对地方。希望有经验的大哥帮个忙。当然大姐也行。总之,不胜感激!

解决方案 »

  1.   

    import   java.awt.*; 
    import   javax.swing.*; public   class   Test   extends   JPanel   {                 public   Test()   { 
                                    this.setBackground(Color.BLACK); 
                    }                 @Override 
                    protected   void   paintComponent(Graphics   g)   { 
                                    super.paintComponent(g);                                 //   draw   code 
                                    Graphics2D   g2d   =   (Graphics2D)   g; 
                                    setBackground(Color.blue); 
                                    g2d.setColor(Color.red); 
                                    g2d.setStroke(new   BasicStroke(4f,   0,   0)); 
                                    g2d.drawRect(10,   10,   50,   50); 
                                    g2d.drawLine(10,   40,   60,   40); 
                                    g2d.drawLine(35,   10,   35,   40); 
                    }                 private   static   void   createUIAndShow()   { 
                                    JFrame   frame   =   new   JFrame();                                 Test   test   =   new   Test(); 
                                    frame.getContentPane().add(test);                                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
                                    frame.setSize(300,   399); 
                                    frame.setVisible(true); 
                    }                 public   static   void   main(String[]   args)   { 
                                    javax.swing.SwingUtilities.invokeLater(new   Runnable()   { 
                                                    public   void   run()   { 
                                                                    Test.createUIAndShow(); 
                                                    } 
                                    }); 
                    } } 
      

  2.   


    import  java.awt.*;
    import  javax.swing.*;public  class  Test  extends  JPanel  {                public  Test()  {
                                    this.setBackground(Color.BLACK);
                    }                @Override
                    protected  void  paintComponent(Graphics  g)  {
                                    super.paintComponent(g);                                //  draw  code
                                    Graphics2D  g2d  =  (Graphics2D)  g;
                                    setBackground(Color.blue);
                                    g2d.setColor(Color.red);
                                    g2d.setStroke(new  BasicStroke(4f,  0,  0));
                                    g2d.drawRect(10,  10,  50,  50);
                                    g2d.drawLine(10,  40,  60,  40);
                                    g2d.drawLine(35,  10,  35,  40);
                    }                private  static  void  createUIAndShow()  {
                                    JFrame  frame  =  new  JFrame();                                Test  test  =  new  Test();
                                    frame.getContentPane().add(test);                                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                    frame.setSize(300,  399);
                                    frame.setVisible(true);
                    }                public  static  void  main(String[]  args)  {
                                    javax.swing.SwingUtilities.invokeLater(new  Runnable()  {
                                                    public  void  run()  {
                                                                    Test.createUIAndShow();
                                                    }
                                    });
                    }} 
    学习了