javax.swing.JFrame.getBounds()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中javax.swing.JFrame.getBounds()方法的一些代码示例,展示了JFrame.getBounds()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFrame.getBounds()方法的具体详情如下:
包路径:javax.swing.JFrame
类名称:JFrame
方法名:getBounds

JFrame.getBounds介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

/**
 * Use this method to create a screenshot of the JFrame object argFrame.
 *
 * Author(s):
 *   Dejan Lekic
 * License: 
 *   Public Domain
 *
 * @param argFrame JFrame you want to make screenshot of.
 */
public static final void makeScreenshot(JFrame argFrame) {
  Rectangle rec = argFrame.getBounds();
  BufferedImage bufferedImage = new BufferedImage(rec.width, rec.height,
      BufferedImage.TYPE_INT_ARGB);
  argFrame.paint(bufferedImage.getGraphics());

  try {
    // Create temp file.
    File temp = File.createTempFile("screenshot", ".png");

    // Use the ImageIO API to write the bufferedImage to a temporary file
    ImageIO.write(bufferedImage, "png", temp);

    // Delete temp file when program exits.
    temp.deleteOnExit();
  } catch (IOException ioe) {
    LOGGER.debug(ioe.toString());
  } // catch
} // makeScreenshot method

代码示例来源:origin: marytts/marytts

/**
 * Creates new form About
 * 
 * @param parent
 *            parent
 */
public About(JFrame parent) {
  super(parent, true);
  initComponents();
  pack();
  Rectangle parentBounds = parent.getBounds();
  Dimension size = getSize();
  // Center in the parent
  int x = Math.max(0, parentBounds.x + (parentBounds.width - size.width) / 2);
  int y = Math.max(0, parentBounds.y + (parentBounds.height - size.height) / 2);
  setLocation(new Point(x, y));
}

代码示例来源:origin: cytoscape/application

/**
 * Gets the bounds of the applications mainframe.
 *
 * @return Rectangle Object.
 */
public Rectangle getBounds() {
  return frame.getBounds();
}

代码示例来源:origin: org.cytoscape/swing-application-impl

/**
 * Gets the bounds of the applications mainframe.
 *
 * @return Rectangle Object.
 */
public Rectangle getBounds() {
  return frame.getBounds();
}

代码示例来源:origin: sc.fiji/TrakEM2_

public Rectangle getBounds() {
  return frame.getBounds();
}

代码示例来源:origin: de.sciss/scisslib

private void update()
{
  f.getBounds( r );
  lb.setText( "L " + r.x + ", T " + r.y + ", R " + (r.x + r.width) +
        ", B " + (r.y + r.height) + ", W " + r.width +
        ", H " + r.height );
}

代码示例来源:origin: UNIVALI-LITE/Portugol-Studio

@Override
public
void componentShown(final ComponentEvent e) {
  look.reLayout(appWindow.getBounds());
}

代码示例来源:origin: stackoverflow.com

public void captureFrame(JFrame frame, String fileName) throws Exception {
  BufferedImage image = new Robot().createScreenCapture(frame.getBounds());
  ImageIO.write(image, "png", new File(fileName));
}

代码示例来源:origin: UNIVALI-LITE/Portugol-Studio

@Override
public
void componentResized(final ComponentEvent e) {
  look.reLayout(appWindow.getBounds());
}

代码示例来源:origin: stackoverflow.com

public static void main(String args[]) throws Exception {

  final JFrame oldFrame = new JFrame("Test");

  oldFrame.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(WindowEvent e) {
      JFrame newFrame = new JFrame("Test");
      newFrame.setBounds(oldFrame.getBounds());
      newFrame.setVisible(true);
    }
  });
  oldFrame.setSize(400, 300);
  oldFrame.setVisible(true);
}

代码示例来源:origin: stackoverflow.com

public static final void makeScreenshot(JFrame f) {
  Rectangle rec = f.getBounds();
  BufferedImage bufferedImage = new BufferedImage(rec.width, rec.height,
      BufferedImage.TYPE_INT_ARGB);
  f.paint(bufferedImage.getGraphics());

  try {
    // Create temp file
    File temp = File.createTempFile("screenshot", ".png");

    ImageIO.write(bufferedImage, "png", temp);

    // Delete temp file on exit
    temp.deleteOnExit();
  } catch (IOException ioe) {
    LOGGER.debug(ioe.toString());
  } 
}

代码示例来源:origin: antlr/antlrworks

public boolean isVisibleOnScreen() {
  GraphicsEnvironment ge =
      GraphicsEnvironment.getLocalGraphicsEnvironment();
  GraphicsDevice[] gs = ge.getScreenDevices();
  Rectangle fr = (useDesktop?jInternalFrame.getBounds():jFrame.getBounds());
  for (GraphicsDevice g : gs) {
    GraphicsConfiguration dc = g.getDefaultConfiguration();
    if (fr.intersects(dc.getBounds())) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: kaikramer/keystore-explorer

private void initApplicationPosition() {
  Rectangle sizeAndPosition = applicationSettings.getSizeAndPosition();
  int xPos = sizeAndPosition.x;
  int yPos = sizeAndPosition.y;
  if (xPos <= 0 || yPos <= 0) {
    frame.setLocationRelativeTo(null);
  } else {
    frame.setLocation(new Point(xPos, yPos));
  }
  if (!SwingUtilities.isRectangleContainingRectangle(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()),
      frame.getBounds())) {
    jQuickStart.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT));
    frame.setLocationRelativeTo(null);
  }
}

代码示例来源:origin: freeplane/freeplane

private void applyFrameSize(final JFrame frame, int win_x, int win_y) {
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle r = env.getMaximumWindowBounds();
    for(GraphicsDevice device : env.getScreenDevices()) {
      if(!device.equals(env.getDefaultScreenDevice())) {
        Rectangle bounds = device.getDefaultConfiguration().getBounds();
        r.add(bounds);
      }
    }
    frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault()));
    frame.setPreferredSize(new Dimension(Math.min(r.width, frame.getBounds().width), Math.min(r.height, frame.getBounds().height)));
//        frame.setLocation(Math.max(r.x, frame.getBounds().x), Math.max(r.y, frame.getBounds().y));
    frame.setLocation(Math.max(r.x, win_x), Math.max(r.y, win_y));
  }

代码示例来源:origin: UNIVALI-LITE/Portugol-Studio

@Override
  public
  void windowStateChanged(WindowEvent e) {
    int state = e.getNewState();
    if ((state & Frame.ICONIFIED) == 0) {
      look.reLayout(appWindow.getBounds());
    }
  }
};

代码示例来源:origin: net.imagej/ij

void recordGeometry(TreePanel panel) {
  String pTitle = panel.getRootPath().toString();
  pTitle = pStr2Key(pTitle);
  JFrame frame = panel.getFrame();
  if (frame!=null) {
    Rectangle rect=frame.getBounds();
    String xCoord = (new Integer(rect.x)).toString();
    String yCoord = (new Integer(rect.y)).toString();
    String width = (new Integer(rect.width)).toString();
    String height = (new Integer(rect.height)).toString();
    if (pTitle.equals("Control_Panel")) pTitle = "Control_Panel.@Main";
    String geometry = xCoord+" "+yCoord+" "+width+" "+height;
    if (IJ.debugMode) IJ.log("CP.recordGeometry: "+pTitle+" "+geometry);
    Prefs.set(pTitle, geometry);
  }
}

代码示例来源:origin: com.harium.propan/propan-jogl

protected void centerCursor() {
  try {
    Robot robot = new Robot();
    Rectangle bounds =  frame.getBounds();			
    robot.mouseMove(bounds.x+bounds.width/2, bounds.y+bounds.height/2);
  } catch (AWTException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  
}

代码示例来源:origin: org.jdesktop.bsaf/bsaf

private void maybeSaveFrameSize(ComponentEvent e) {
  if (e.getComponent() instanceof JFrame) {
    JFrame f = (JFrame) e.getComponent();
    if ((f.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0) {
      SwingHelper.putWindowNormalBounds(f, f.getBounds());
    }
  }
}

代码示例来源:origin: net.java.abeille/abeille

/**
 * Saves the frame state to the object store and
 */
void shutDown() {
  try {
    ObjectStore os = (ObjectStore) JETARegistry.lookup(ComponentNames.APPLICATION_STATE_STORE);
    FrameState fstate;
    if (m_properties_frame == null)
      fstate = new FrameState();
    else
      fstate = new FrameState(m_properties_frame.getBounds());
    os.store(ID_PROPERTIES_FRAME_STATE, fstate);
  } catch (Exception e) {
    // ignore
  }
}

代码示例来源:origin: net.java.dev.appframework/appframework

private void maybeSaveFrameSize(ComponentEvent e) { 
  if (e.getComponent() instanceof JFrame) {
    JFrame f = (JFrame)e.getComponent();
    if ((f.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0) {
      String clientPropertyKey = "WindowState.normalBounds";
      f.getRootPane().putClientProperty(clientPropertyKey, f.getBounds());
    }
  }
}
public void componentResized(ComponentEvent e) { maybeSaveFrameSize(e); }

相关文章

JFrame类方法