2010-06-18 4 views
1

불투명도뿐만 아니라 Swing 내 불투명도의 기본 색을 변경하고 싶은 JWindow를 만들고 싶습니다.검은 색 불투명도가있는 JWindow

그래서 예를 들어, 내가 쓰는 경우 :

AWTUtilities.setWindowOpacity(this, 0.5f); 

이 정확히 내가 한 가지 예외가 원하는 것을 할 것, 색상은 흰색입니다. 색상을 검정색으로 만들려면 어떻게해야합니까?

나는 "이"...

답변

2
 window.getContentPane().setBackground(Color.BLACK); 
0

투명 JWindow의에 setBackground(Color.Black) 등 모든 것을 시도했습니다.

public class TransparentWindow{ 

    JWindow window; 

    public TransparentWindow(){ 
     initializeTransparentWindow(); 
    } 

    private void initializeTransparentWindow() { 
     // searching graphical configuration that provide transparent window 
     GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); 
     GraphicsDevice[] devices = env.getScreenDevices(); 
     GraphicsConfiguration translucencyCapableGC = null; 
     for (int i = 0; i < devices.length && translucencyCapableGC == null; i++) { 
      GraphicsConfiguration[] configs = devices[i].getConfigurations(); 
      for (int j = 0; j < configs.length && translucencyCapableGC == null; j++) { 
       if (AWTUtilities.isTranslucencyCapable(configs[j])) { 
        translucencyCapableGC = configs[j]; 
       } 
      } 
     } 
     if (translucencyCapableGC != null) { 
      window = new JWindow(translucencyCapableGC) { 
       @Override 
       public void paint(Graphics g) { 
        if (getWidth() > 4 && getHeight() > 4) { 
         g.clearRect(0, 0, getWidth(), getHeight()); 
         g.setColor(new Color(0x0, 0x0, 0x0, 0xaa)); 
         g.fillRect(0, 0, 1, getHeight()); 
         g.fillRect(0, 0, getWidth(), 1); 
         g.fillRect(0, getHeight() - 1, getWidth(), 1); 
         g.fillRect(getWidth() - 1, 0, 1, getHeight()); 
         g.setColor(new Color(0x0, 0x0, 0x0, 0x10)); 
         g.fillRect(1, 1, getWidth() - 1, getHeight() - 1); 
        } 
       }; 
      }; 
      AWTUtilities.setWindowOpaque(window, false); 
     } 
     else { 
      window = new JWindow(); 
      AWTUtilities.setWindowOpacity(window, 0.5f); 
     } 
    }