2017-12-15 2 views
0

나는 화면 오버레이로 사용할 수 있도록 항상 투명하고 초점이 맞지 않는 JFrame입니다. 그것은 작동하지만 문제는 다음과 같습니다. 커서를 어딘가에 집어 넣으면 무언가를 그렸습니다. 실제로 커서가 커서 위에 있기 때문에 실제로 포커스가있는 창을 클릭 할 수 없습니다. 이 문제를 해결할 방법이 있습니까? 스윙 화면 오버레이로 마우스를 그릴 때 마우스가 간섭을받습니다.

frame.setOpacity(0.0f); 

How to Create Translucent and Shaped Windows에 스윙 튜토리얼 섹션을 읽어

public class ExternalOverlay extends JFrame implements ActionListener { 

    public Timer timer; 
    private float[] res; 
    private final int FRAMERATE = 60; 

    public ExternalOverlay() { 
     this.setUndecorated(true); 
     this.setBackground(new Color(0, 0, 0, 0)); 
     float[] res = this.getRes(); 
     this.setBounds(0, 0, (int)res[0], (int)res[1]); 
     this.setAlwaysOnTop(true); 
     this.getContentPane().setLayout(new java.awt.FlowLayout()); 
     this.setVisible(true); 
     this.setAutoRequestFocus(false); 
     this.setFocusableWindowState(false); 
     this.timer = new Timer(1000/FRAMERATE, this); 
     timer.start(); 
    } 

    private float[] getRes() { 
     if (this.res != null) return res; 
     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 
     double width = screenSize.getWidth(); 
     double height = screenSize.getHeight(); 
     return new float[] {(float) width, (float) height}; 
    } 

    @Override 
    public void actionPerformed(ActionEvent e) { 
     this.repaint(); 
    } 


    public void draw(Graphics g) { 

    } 

    @Override 
    public void paint(Graphics g) { 
    // draw 
    } 
} 

답변

0

나는 당신이 사용되어야한다

투명한 JFrame의가 있습니다. 시작하기 좋은 곳을 찾기 위해 TranslucentWindowDemo 코드를 다운로드하십시오.

+1

투명한 배경이 있다고 말해야합니다. – Babbaj

+0

@Babbaj, 투명한 배경이란 무엇입니까? 프레임이 항상 오버탑이므로 오버레이로 사용할 수 있습니다. 그러면 프레임이 다른 창 위에 놓여져 바탕 화면의 다른 창을 볼 수 있습니다. 사용자 정의 페인팅을 수행하려는 경우 JPanel의 paintComponent() 메서드를 재정의 한 다음 프레임에 패널을 추가해야합니다. 질문이 명확하지 않으므로 문제를 나타내는 적절한 [mcve]를 게시하십시오. – camickr

관련 문제