I'm trying to create a simple piano application using Java, and I'm stuck at creating the keys.
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.
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