找到你要的答案

Q:Jbutton shows up in front of jpanel on jlayeredpane when moving mouse over it

Q:JButton在JLayeredPane当移动鼠标录入前出现

I have a JLayeredPane, with a JButton and JPanel. Both are the same size and at the same location. The JPanel is transparent with a LineBorder and the button also, so that there is another border in front of the Jbutton, but when I move the mouse over the panel the Button appears in front of it. I want the button to move and JPanel to stay put, but why does the JButton move in front of the JPanel when moving mouse over it?

我有一个JLayeredPane,一个JButton和JPanel。两者大小相同,位置相同。这是一个lineborder JPanel透明的按钮,所以在JButton前另一个边界,但是当我移动鼠标在按钮出现在它的前面面板。我想要的按钮来移动和JPanel留在原地,但为什么JButton移动的移动鼠标时录入前吗?

answer1: 回答1:

, but why does the JButton move in front of the JPanel when moving mouse over it?

Mouse events are generated as you move your mouse around the frame.

In this case a "mouse entered" event is being generated as the mouse moves over the button. By default a button has a rollover effect and the button needs to be painted, so it is painted on top of the panel.

Not sure, buy you might be able to turn off this effect by using:

button.setRolloverEnabled( false );

However, when you click the button you will have the same problem.

,但为什么JButton移动的移动鼠标时录入前吗?

当鼠标移动到框架周围时,会产生鼠标事件。

在这种情况下,一个“鼠标输入”事件正在生成的鼠标移动按钮。默认情况下,按钮具有翻转效果,按钮需要被绘制,所以它被绘制在面板的顶部。

不确定,买你可能会关闭这个效果使用:

button.setRolloverEnabled( false );

然而,当你点击按钮,你会有同样的问题。

java  swing