-1

I'm makeing a game where I want to be able to click on a rectangle and perform a piece of code.

I want the button to be transparent and at x, y coordinates with the right size... I've been searching and not found anything of help. So can someone of you help?

I'm Using Java 1.7

I've tried

button.setOpaque(false);
button.setContentAreaFilled(false);
button.setBorderPainted(false);

button.setVisible(false);

bDice1.setLayout(null);
bDice1.setLocation(30, 40);
bDice1.setSize(12, 12);
Qwe500
  • 105
  • 1
  • 2
  • 8
  • Is it java or javascript? – Ankit Jaiswal Jun 26 '13 at 13:32
  • Is there anything you have done to try to solve this problem? We will be more willing to answer your question if you tell us what you have tried so far. (Helpful links for asking better questions: [ask], [help]) – tckmn Jun 26 '13 at 13:33
  • java 1.7 I use eclipse – Qwe500 Jun 26 '13 at 13:34
  • what graphical toolkit are you using? How did you design the window where you put that button? – zmo Jun 26 '13 at 14:43
  • Don't use `setVisible(false)`. The button won't get painted. You also need to add an ActionListener to the button. Post your [SSCCE](http://sscce.org/) that demonstrates the problem if you need more help – camickr Jun 26 '13 at 15:16

1 Answers1

2

Are you able to capture mouse clicks for the underlying window where the proposed transparent button would be placed?

If the answer to that is yes the why not have the mouse click handler for the underlying window do a quick check at each click to determine if the mouse is in the desired rectangular area?

With this scheme you can eliminate the need for the transparent button entirely.

Michael Karas
  • 248
  • 2
  • 12