【发布时间】:2011-03-29 08:56:59
【问题描述】:
我想在运行时通过单击其边框并拖动它来调整JButton 的大小。谁能用示例代码解释我如何做到这一点。
public void mouseDragged(MouseEvent E)
{
Point point= E.getPoint();
//JButton get = floor_plan.dynamicButtons.get(E.getComponent());
JButton get=(JButton) E.getComponent();
int height = get.getHeight();
int width = get.getWidth();
int X=E.getXOnScreen();
int Y=E.getYOnScreen();
if(floor_plan.resize==1)
if (floor_plan.isHeld) {
System.out.println(X);
System.out.println(Y);
get.setPreferredSize(
new Dimension(floor_plan.grabbedDimension.width -
(floor_plan.grabbedPoint.x - point.x),
floor_plan.grabbedDimension.height -
(floor_plan.grabbedPoint.y - point.y)));
get.setBounds(new Rectangle(get.getLocation(), get.getPreferredSize()));
return;
}
System.out.println("height:"+height);
System.out.println("width:"+width);
get.setBounds(X-240,Y-125,height,width);
}
【问题讨论】: