这是我的问题:我有一个 jpanel,里面有三个面板。垂直分隔面板、聊天输入面板和聊天输入面板。主jpanel,chatpanel,实现mousemotionlistener,代码如下:
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();
}
}
问题是,由于某种原因,当您将鼠标移动到垂直面板分隔符上时,它会变为调整大小的光标,但是当您向上移动它时,无需拖动,它就会保持为调整大小的光标。此外,从打印语句来看,当鼠标向上进入聊天输出时,e.getY() 的值不会增加,它保持在垂直分隔面板的范围内。它就像聊天输出默认鼠标监听器覆盖了聊天面板上的鼠标监听器并且什么都不做。有人可以告诉我这里发生了什么以及如何解决这个问题吗?