1

I found lots of question like this but don't find the answer of exactly this question. I want to make a transparent rectangle for example and it will be just for design not for functionality. So I want when I click on its border and I have a button in another window under the border of my rectangle - the button to be clicked. Is it possible? This is my code but it does not work as intended.

public class ClickThroughWindow {

    public static final int RECT_SIZE = 80;

    public static void main(String[] args) {

        TestPanel panel = new TestPanel();
        panel.setPreferredSize(new Dimension(RECT_SIZE, RECT_SIZE));
        panel.setOpaque(false);

        JFrame frame = new JFrame("Crossfire");
        // Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        // frame.setLocation(dim.width / 2 - frame.getSize().width / 2 -
        // RECT_SIZE
        // / 2, dim.height / 2 - frame.getSize().height / 2 - RECT_SIZE
        // / 2);
        frame.setUndecorated(true);
        frame.setBackground(new Color(0, 0, 0, 0));
        frame.add(panel);
        frame.setAlwaysOnTop(true);
        frame.pack();
        frame.setVisible(true);
    }
}

public class TestPanel extends JPanel {

    private static final long serialVersionUID = 2446519137290816513L;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g.create();
        g2d.setColor(getBackground());
        g2d.setStroke(new BasicStroke(40));
        g2d.setColor(Color.BLACK);
        g2d.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
        g2d.dispose();
    }
}

here is an example: postimg.org/image/t4gzczzc3. When click where the arrow points I want to go to first tab of my browser. (even my program is on top)

naskobg13
  • 79
  • 1
  • 6

0 Answers0