I want to resize the JButton at runtime by clicking on its border and draging it. Can anyone explain me how to do it with a sample code.
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);
}
Well, this might do it for you. When adding the new button, simply add a
ResizableButtoninstead.Note, it will resize no matter where you click on it.
Below is code for a button that moves or re-sizes based on whether or not the Alt button is pressed.: