這裏是我的問題:我有一個jpanel,它有三個面板。一個verticalseperator面板,一個chatouput面板和chatinput面板。主要的JPanel,chatpanel,實現的MouseMotionListener,並具有以下代碼:jtextarea鼠標事件覆蓋容器鼠標事件
public void mouseMoved(MouseEvent e) {
int y = e.getY();
//change cursor look if hovering over vertical spacer
if(y >= (int)(verticalPanelSeperator.getLocation().getY()) && y <= (int)(verticalPanelSeperator.getLocation().getY() + verticalPanelSeperator.getHeight())) {
setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
}
else {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
public void mouseDragged(MouseEvent e) {
//vertical spacer can be draged up/down to change height of input/output areas
if(getCursor().getType() == Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR).getType()) {
int edge = (int)this.getLocation().getY();
int cur = e.getY();
int height = this.getHeight();
output.setHeightPercent((((double)(cur-edge))/height));
output.componentResized(new ComponentEvent(this, 1));
input.setHeightPercent((((double)(height-cur-edge))/height));
input.componentResized(new ComponentEvent(this, 2));
e.consume();
}
}
的問題是,由於某種原因,當你在verticalpanelseperator移動鼠標,它變成一個大小調整光標,但是當你移動它在不拖動的情況下保持爲調整大小的光標。此外,從print語句中,當鼠標進入聊天輸出時,e.getY()的值不會增加,它會保持在verticalseperatorpanel的範圍內。它像chatoutput默認的mouselistener正在覆蓋chatpanel上的那個,並且什麼都不做。有人能告訴我這裏發生了什麼,以及如何解決這個問題?