调整大小代码与鼠标移动不符 [英] Resize code does not correspond with mouse movement

查看:74
本文介绍了调整大小代码与鼠标移动不符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码可以动态调整聊天面板的大小,但是它不会根据鼠标移动.发生的事情是鼠标的移动速度快于调整面板大小的速度.例如,在任何应用程序中,当您单击两个窗口之间的边框并拖动它时,鼠标都会停留在您要单击的部分上,而当前却没有发生.这是我的代码.请让我知道是否需要更多

I have some code to resize a chatpanel dynamically, but it does not move according to the mouse. What happens is the mouse moves at a faster rate than the panel gets resized. For example, how I want it to be, is in any application, when you click on the border between two windows, and drag it, the mouse stays along with the piece you are clicking on, and currently this is not happening. here is my code. please let me know if you need more

public void mouseDragged(MouseEvent e) {
    if(getCursor().getType() == Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR).getType()) {
        owner.adjust((int)MouseInfo.getPointerInfo().getLocation().getY());
        System.out.println("vertpanel: "+(int)MouseInfo.getPointerInfo().getLocation().getY());
    }
}
public void adjust(int adjustment) {
int height = this.getHeight();
    System.out.println((((double)(adjustment))/height)+":"+(((double)(height-adjustment))/height));
output.setHeightPercent((((double)(adjustment))/height));
output.componentResized(new ComponentEvent(this, 1));
input.setHeightPercent((((double)(height-adjustment))/height));
input.componentResized(new ComponentEvent(this, 2));
}

有一个主面板,一个聊天面板,其中有两个较小的面板,一个聊天输入和一个聊天输出

there is one main panel, a chatpanel, and within it, there are two smaller panels, a chat input and a chat output

推荐答案

根据代码无法准确判断出您在做什么.

Can't tell exactly what you are doing based on your code.

我建议您不要手动设置输出和输入组件的尺寸.您应该让布局管理器确定在调整父容器大小时如何调整每个组件的大小.

I would suggest that you should NOT be manually setting the dimensions of the output and input coponents. You should let the layout manager determine how to resize each component as the parent container is resized.

因此,在您调整大小的代码中,您需要在调整大小后在父容器上调用revalidate().

So in your resize code you would need to invoke revalidate() on the parent container as it is resized.

查看调整组件大小.只要使用setAutoLayout(true),您就应该能够使用ComponentResizer类.

Check out Resizing Components. You should be able to use the ComponentResizer class as long as you use setAutoLayout(true).

这篇关于调整大小代码与鼠标移动不符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆