1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
public void componentResized(ComponentEvent event)
{
if(dimensions != null && this.isVisible() && dimensions.getWidth() != 0 && dimensions.getHeight() != 0)
{
double xfactor = this.getBounds().getWidth() / dimensions.getWidth();
double yfactor = this.getBounds().getHeight() / dimensions.getHeight();
//if(xfactor > 1.1 || yfactor > 1.1 || xfactor < 0.9 || yfactor < 0.9)
//{
//System.out.println("XFACTOR = " + xfactor + ", YFACTOR = " + yfactor);
for(Component c : this.getComponents())
{
this.resizeComponent(c, xfactor, yfactor);
}
dimensions = this.getBounds();
//}
}
else
{
dimensions = this.getBounds();
}
this.repaint();
//System.out.println("WIDTH = " + this.getWidth() + " HEIGHT = " + this.getHeight());
}
private void resizeComponent(Component c, double xfactor, double yfactor)
{
if(!(c instanceof WindowsInternalFrameTitlePane))
{
Rectangle original = c.getBounds();
int newX= (int)Math.round(original.getX() * xfactor);
int newY = (int)Math.round(original.getY() * yfactor);
int newW = (int)Math.round(original.getWidth() * xfactor);
int newH = (int)Math.round(original.getHeight() * yfactor);
Dimension newDim = new Dimension(newW, newH);
c.setPreferredSize(newDim);
c.setSize(newDim);
c.setBounds(newX, newY, newW,newH);
if(c instanceof Container)
{
Container cc = (Container)c;
for(Component ch : cc.getComponents())
{
this.resizeComponent(ch, xfactor, yfactor);
}
}
c.repaint();
}
} |
Partager