List of usage examples for javax.swing JWindow pack
@SuppressWarnings("deprecation") public void pack()
From source file:Main.java
public static void main(String[] arg) throws Exception { Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); Robot robot = new Robot(); BufferedImage image = robot//from w ww .j av a 2 s . com .createScreenCapture(new Rectangle(0, 0, (int) screenDim.getWidth(), (int) screenDim.getHeight())); JWindow window = new JWindow(new JFrame()); window.getContentPane().setLayout(new BorderLayout()); window.getContentPane().add(BorderLayout.CENTER, new JLabel(new ImageIcon(image))); window.pack(); window.setVisible(true); }
From source file:com.totsp.sotu.app.ScreenAreaWatcher.java
/** Creates a new instance of ScreenWatcher */ public ScreenAreaWatcher(final Configuration config) throws AWTException { super();/*w w w .j a va2 s . c om*/ this.config = config; System.out.println(config.getWidth() + "x" + config.getHeight()); JPanel jp = null; JWindow top = new JWindow(); top.setBackground(GREEN); top.setLocation(0, 0); top.setAlwaysOnTop(true); jp = new JPanel(); jp.setBackground(GREEN); top.add(jp); top.pack(); top.setSize(config.getWidth(), config.getBorderSize()); JWindow bottom = new JWindow(); bottom.setBackground(GREEN); bottom.setLocation(0, config.getHeight() - config.getBorderSize()); bottom.setAlwaysOnTop(true); jp = new JPanel(); jp.setBackground(GREEN); bottom.add(jp); bottom.pack(); bottom.setSize(config.getWidth(), config.getBorderSize()); JWindow left = new JWindow(); left.setBackground(GREEN); left.setLocation(0, 0); left.setAlwaysOnTop(true); jp = new JPanel(); jp.setBackground(GREEN); left.add(jp); left.pack(); left.setSize(config.getBorderSize(), config.getHeight()); JWindow right = new JWindow(); right.setLocation(config.getWidth() - config.getBorderSize(), 0); right.setAlwaysOnTop(true); jp = new JPanel(); jp.setBackground(GREEN); right.add(jp); right.pack(); right.setSize(config.getBorderSize(), config.getHeight()); top.setVisible(true); bottom.setVisible(true); left.setVisible(true); right.setVisible(true); windows = new JWindow[4]; windows[0] = top; windows[1] = bottom; windows[2] = left; windows[3] = right; MouseInputAdapter adapter = new Adapter(windows); top.addMouseListener(adapter); top.addMouseMotionListener(adapter); bottom.addMouseListener(adapter); bottom.addMouseMotionListener(adapter); left.addMouseListener(adapter); left.addMouseMotionListener(adapter); right.addMouseListener(adapter); right.addMouseMotionListener(adapter); timer.schedule(new ImageUpdateTimerTask(this), 0, config.getMaxUpdateInterval()); this.addPropertyChangeListener("image", new PropertyChangeListener() { HttpClient client = new HttpClient(); public void propertyChange(PropertyChangeEvent propertyChangeEvent) { BufferedImage img = (BufferedImage) propertyChangeEvent.getNewValue(); try { File outputFile = File.createTempFile("save-" + System.currentTimeMillis(), ".png"); JAI.create("filestore", img, outputFile.getCanonicalPath(), "PNG", null); System.out.println("Temp File: " + outputFile.getCanonicalPath()); MultipartPostMethod method = new MultipartPostMethod( config.getServerUrl() + "/ImagePublishingServlet"); method.addParameter("adminPassword", config.getAdminPassword()); method.addParameter("conversation", config.getConversationName()); method.addParameter("image", outputFile); client.executeMethod(method); } catch (Exception e) { System.err.println("Error handling image"); e.printStackTrace(); } } }); }
From source file:org.apache.log4j.chainsaw.LogUI.java
/** * Shutsdown by ensuring the Appender gets a chance to close. *///w ww .ja v a 2s.c om public boolean shutdown() { if (getApplicationPreferenceModel().isConfirmExit()) { if (JOptionPane.showConfirmDialog(LogUI.this, "Are you sure you want to exit Chainsaw?", "Confirm Exit", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) != JOptionPane.YES_OPTION) { return false; } } final JWindow progressWindow = new JWindow(); final ProgressPanel panel = new ProgressPanel(1, 3, "Shutting down"); progressWindow.getContentPane().add(panel); progressWindow.pack(); Point p = new Point(getLocation()); p.move((int) getSize().getWidth() >> 1, (int) getSize().getHeight() >> 1); progressWindow.setLocation(p); progressWindow.setVisible(true); Runnable runnable = new Runnable() { public void run() { try { int progress = 1; final int delay = 25; handler.close(); panel.setProgress(progress++); Thread.sleep(delay); pluginRegistry.stopAllPlugins(); panel.setProgress(progress++); Thread.sleep(delay); panel.setProgress(progress++); Thread.sleep(delay); } catch (Exception e) { e.printStackTrace(); } fireShutdownEvent(); performShutdownAction(); progressWindow.setVisible(false); } }; if (OSXIntegration.IS_OSX) { /** * or OSX we do it in the current thread because otherwise returning * will exit the process before it's had a chance to save things * */ runnable.run(); } else { new Thread(runnable).start(); } return true; }
From source file:org.geopublishing.atlasViewer.swing.AtlasViewerGUI.java
/** * Called via SingleInstanceListener / SingleInstanceService. Shows a * splashscreen and bring the existing instance to the front. *///from w w w . java2 s .c o m @Override public void newActivation(String[] arg0) { LOGGER.info( "A second instance of AtlasViewer has been started.. The single instance if requesting focus now..."); /* * Showing the Spalshscreen for one secong */ try { final URL splashscreenUrl = atlasConfig.getResource(AtlasConfig.SPLASHSCREEN_RESOURCE_NAME); if (splashscreenUrl != null) { JWindow splashWindow = new JWindow(atlasJFrame); JPanel panel = new JPanel(new BorderLayout()); ImageIcon icon = new ImageIcon(splashscreenUrl); panel.add(new JLabel(icon), BorderLayout.CENTER); panel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); splashWindow.getContentPane().add(panel); splashWindow.getRootPane().setOpaque(true); splashWindow.pack(); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); splashWindow.setLocation((int) (d.getWidth() - splashWindow.getWidth()) / 2, (int) (d.getHeight() - splashWindow.getHeight()) / 2); splashWindow.setVisible(true); Thread.sleep(1500); splashWindow.dispose(); splashWindow = null; } } catch (Exception e) { LOGGER.warn("Singleinstance.newActivation had problems while showing the splashscreen:", e); } if (getJFrame() != null) { if (!getJFrame().isShowing()) getJFrame().setVisible(true); /* In case that it has been iconified */ getJFrame().setExtendedState(Frame.NORMAL); getJFrame().requestFocus(); getJFrame().toFront(); } }