Пример #1
0
 void ajustarYCentrar(JComponent porAjustar, JComponent ajustador) {
   // Se agregan 30 de alto y 6 de ancho por adornos de la ventana
   porAjustar.setSize(
       ajustador.getMinimumSize().getSize().width + 16,
       ajustador.getMinimumSize().getSize().height + 44);
   int x = Math.round(Principal.sysAncho / 2) - Math.round(porAjustar.getBounds().width / 2);
   int y = Math.round(Principal.sysAlto / 2) - Math.round(porAjustar.getBounds().height / 2);
   porAjustar.setLocation(x, y);
 }
Пример #2
0
  /*
   *  Create a BufferedImage for Swing components.
   *  The entire component will be captured to an image.
   *
   *  @param	 component Swing component to create image from
   *  @param	 fileName name of file to be created or null
   *  @return	image the image for the given region
   *  @exception IOException if an error occurs during writing
   */
  public static BufferedImage createImage(JComponent component, String fileName)
      throws IOException {
    Dimension d = component.getSize();

    if (d.width == 0) {
      d = component.getPreferredSize();
      component.setSize(d);
    }

    Rectangle region = new Rectangle(0, 0, d.width, d.height);
    return ScreenCapture.createImage(component, region, fileName);
  }