List of usage examples for java.awt Frame getInsets
public Insets getInsets()
From source file:Snippet156.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("SWT Image"); ImageData data;//ww w . j a va 2 s . co m if (args.length > 0) { String fileName = args[0]; data = new ImageData(fileName); } else { data = createSampleImage(display); } final Image swtImage = new Image(display, data); final BufferedImage awtImage = convertToAWT(data); final Image swtImage2 = new Image(display, convertToSWT(awtImage)); shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event e) { int y = 10; if (swtImage != null) { e.gc.drawImage(swtImage, 10, y); y += swtImage.getBounds().height + 10; } if (swtImage2 != null) { e.gc.drawImage(swtImage2, 10, y); } } }); Frame frame = new Frame() { public void paint(Graphics g) { Insets insets = getInsets(); if (awtImage != null) { g.drawImage(awtImage, 10 + insets.left, 10 + insets.top, null); } } }; frame.setTitle("AWT Image"); shell.setLocation(50, 50); Rectangle bounds = swtImage.getBounds(); shell.setSize(bounds.width + 50, bounds.height * 2 + 100); Point size = shell.getSize(); Point location = shell.getLocation(); Insets insets = frame.getInsets(); frame.setLocation(location.x + size.x + 10, location.y); frame.setSize(size.x - (insets.left + insets.right), size.y - (insets.top + insets.bottom)); frame.setVisible(true); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (swtImage != null) swtImage.dispose(); if (swtImage2 != null) swtImage.dispose(); frame.dispose(); System.exit(0); }
From source file:AWTBufferedImageSWTImage.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("SWT Image"); ImageData data;/*from w w w .j a v a 2 s .c om*/ if (args.length > 0) { String fileName = args[0]; data = new ImageData(fileName); } else { data = createSampleImage(display); } final Image swtImage = new Image(display, data); final BufferedImage awtImage = convertToAWT(data); final Image swtImage2 = new Image(display, convertToSWT(awtImage)); shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event e) { int y = 10; if (swtImage != null) { e.gc.drawImage(swtImage, 10, y); y += swtImage.getBounds().height + 10; } if (swtImage2 != null) { e.gc.drawImage(swtImage2, 10, y); } } }); Frame frame = new Frame() { public void paint(Graphics g) { Insets insets = getInsets(); if (awtImage != null) { g.drawImage(awtImage, 10 + insets.left, 10 + insets.top, null); } } }; frame.setTitle("AWT Image"); shell.setLocation(50, 50); Rectangle bounds = swtImage.getBounds(); shell.setSize(bounds.width + 50, bounds.height * 2 + 100); Point size = shell.getSize(); Point location = shell.getLocation(); Insets insets = frame.getInsets(); frame.setLocation(location.x + size.x + 10, location.y); frame.setSize(size.x - (insets.left + insets.right), size.y - (insets.top + insets.bottom)); frame.setVisible(true); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (swtImage != null) swtImage.dispose(); if (swtImage2 != null) swtImage.dispose(); frame.dispose(); display.dispose(); /* * Note: If you are using JDK 1.3.x, you need to use System.exit(0) at the * end of your program to exit AWT. This is because in 1.3.x, AWT does not * exit when the frame is disposed, because the AWT thread is not a daemon. * This was fixed in JDK 1.4.x with the addition of the AWT Shutdown thread. */ }
From source file:org.eclipse.swt.snippets.Snippet156.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("SWT Image"); ImageData data;//ww w. j a v a 2 s. co m if (args.length > 0) { String fileName = args[0]; data = new ImageData(fileName); } else { data = createSampleImage(display); } final Image swtImage = new Image(display, data); final BufferedImage awtImage = convertToAWT(data); final Image swtImage2 = new Image(display, convertToSWT(awtImage)); shell.addListener(SWT.Paint, e -> { int y = 10; if (swtImage != null) { e.gc.drawImage(swtImage, 10, y); y += swtImage.getBounds().height + 10; } if (swtImage2 != null) { e.gc.drawImage(swtImage2, 10, y); } }); Frame frame = new Frame() { @Override public void paint(Graphics g) { Insets insets = getInsets(); if (awtImage != null) { g.drawImage(awtImage, 10 + insets.left, 10 + insets.top, null); } } }; frame.setTitle("AWT Image"); shell.setLocation(50, 50); Rectangle bounds = swtImage.getBounds(); shell.setSize(bounds.width + 50, bounds.height * 2 + 100); Point size = shell.getSize(); Point location = shell.getLocation(); Insets insets = frame.getInsets(); frame.setLocation(location.x + size.x + 10, location.y); frame.setSize(size.x - (insets.left + insets.right), size.y - (insets.top + insets.bottom)); frame.setVisible(true); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (swtImage != null) swtImage.dispose(); if (swtImage2 != null) swtImage.dispose(); frame.dispose(); display.dispose(); /* Note: If you are using JDK 1.3.x, you need to use System.exit(0) at the end of your program to exit AWT. * This is because in 1.3.x, AWT does not exit when the frame is disposed, because the AWT thread is not a daemon. * This was fixed in JDK 1.4.x with the addition of the AWT Shutdown thread. */ }
From source file:com.jcraft.weirdx.XWindow.java
private void addComponentListener(java.awt.Frame foo) { final java.awt.Frame frame = foo; frame.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent e) { if (parent == null) return; Rectangle rectangle = frame.getBounds(); if (rectangle.width == 0 || rectangle.height == 0) return; if (frame_width != rectangle.width || frame_height != rectangle.height) { Insets insets = frame.getInsets(); synchronized (XWindow.LOCK) { try { Point point = frame.getLocation(); int ww = rectangle.width - insets.left - insets.right - borderWidth * 2; int hh = rectangle.height - insets.top - insets.bottom - borderWidth * 2; if (ww > 0 && hh > 0) { ddxwindow.setSize(ww, hh); frame.pack(); Event event = new Event(); event.mkConfigureNotify(id, id, (rectangle.x + insets.left), (rectangle.y + insets.top), ww, hh, borderWidth, (attr & (1 << 16)) != 0 ? 1 : 0); sendEvent(event, 1, null); frame_x = rectangle.x; frame_y = rectangle.y; frame_width = rectangle.width; frame_height = rectangle.height; }/*from www . j a va 2 s . co m*/ } catch (Exception ee) { LOG.error(ee); } } } } }); }