Java GUI, creating piano keys using JButton

1.6k views Asked by At

I'm trying to create a simple piano application using Java, and I'm stuck at creating the keys.

Awesome

So what I have is a bunch of (Black) JButtons on top of (White) JButtons, but whenever I click the white buttons, it covers the black buttons.

So my question is; how do I implement this so the black JButtons would stay on top of the white ones.

1

There are 1 answers

0
Aleks G On BEST ANSWER

I'm not sure how you're laying out your buttons in the first place. I suggest you use JLayeredPane for the layout. With it, you specify z-index of each component - and it takes care of the rest. Have a look here: http://docs.oracle.com/javase/tutorial/uiswing/components/layeredpane.html#depth