[英]How to resize a JFrame manually?
我正在尝试通过拖动JPanel来手动调整JFrame的大小。 这是我所做的。 目前可以正常使用,但屏幕仍然闪烁,并且尺寸调整不正确
我希望它发生的是,当我单击Jpanel并将其拖动时,JFrame应该自动调整为X坐标和Y坐标所在的位置。
public void mouseDragged(MouseEvent e) {
// Sets width, height and moved X and Y coordinates
int currentwidth = this.getWidth();
int currentheight = this.getHeight();
int newwidth = 0;
int newheight = 0 ;
int thisX = this.getX();
int thisY = this.getY();
// Calculates the moving distance
int xMoved = (thisX + e.getX()) - (thisX + initialClick.x);
int yMoved = (thisY + e.getY()) - (thisY + initialClick.y);
// Checks which component the mouse is clicked on
if(e.getComponent() == reszingbit){
// Calculates the new height and width
newwidth = 200 + xMoved;
newheight = 200 + yMoved;
// Making sure that the new height and width is not less than actual size
if(newwidth >= 200 && newheight >= 200){
this.setSize(newwidth,newheight);
}
}
200是实际的高度和宽度。
信息很少,但可能需要将大小计算更改为:
newwidth = this.getWidth() + xMoved;
newheight = this.getHeight() + yMoved;
移动大小的计算应如下所示:
int xMoved = e.getX() - initialClick.x;
int yMoved = e.getY() - initialClick.y;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.