Java Code Examples for java.awt.Window#validate()
The following examples show how to use
java.awt.Window#validate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WindowMouseHandler.java From littleluck with Apache License 2.0 | 6 votes |
public void mouseReleased(MouseEvent e) { Window window = (Window) e.getSource(); if (dragCursor != 0 && window != null && !window.isValid()) { // Some Window systems validate as you resize, others won't, // thus the check for validity before repainting. window.validate(); if(window instanceof JFrame) { ((JFrame)window).getRootPane().repaint(); } } // 松开鼠标时重置状态 isMovingWindow = false; dragCursor = 0; }
Example 2
Source File: SeaGlassRootPaneUI.java From seaglass with Apache License 2.0 | 6 votes |
/** * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) */ public void mouseDragged(MouseEvent ev) { Window w = (Window) ev.getSource(); Point pt = ev.getPoint(); if (isMovingWindow) { Point eventLocationOnScreen = ev.getLocationOnScreen(); w.setLocation(eventLocationOnScreen.x - dragOffsetX, eventLocationOnScreen.y - dragOffsetY); } else if (dragCursor != 0) { Rectangle r = w.getBounds(); Rectangle startBounds = new Rectangle(r); Dimension min = w.getMinimumSize(); switch (dragCursor) { case Cursor.E_RESIZE_CURSOR: adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0); break; case Cursor.S_RESIZE_CURSOR: adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height); break; case Cursor.N_RESIZE_CURSOR: adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY)); break; case Cursor.W_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0); break; case Cursor.NE_RESIZE_CURSOR: adjust(r, min, 0, pt.y - dragOffsetY, pt.x + (dragWidth - dragOffsetX) - r.width, -(pt.y - dragOffsetY)); break; case Cursor.SE_RESIZE_CURSOR: adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, pt.y + (dragHeight - dragOffsetY) - r.height); break; case Cursor.NW_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, pt.y - dragOffsetY, -(pt.x - dragOffsetX), -(pt.y - dragOffsetY)); break; case Cursor.SW_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), pt.y + (dragHeight - dragOffsetY) - r.height); break; default: break; } if (!r.equals(startBounds)) { w.setBounds(r); // Defer repaint/validate on mouseReleased unless dynamic // layout is active. if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) { w.validate(); getRootPane().repaint(); } } } }
Example 3
Source File: Session.java From FancyBing with GNU General Public License v3.0 | 5 votes |
private void setSizeChecked(Window window, int width, int height) { Dimension screenSize = getScreenSize(); width = Math.min(width, screenSize.width); height = Math.min(height, screenSize.height); window.setSize(width, height); window.validate(); }
Example 4
Source File: LizziePane.java From lizzie with GNU General Public License v3.0 | 4 votes |
public void mouseDragged(MouseEvent e) { Window w = (Window) e.getSource(); Point pt = e.getPoint(); if (isMovingWindow) { Point eventLocationOnScreen = e.getLocationOnScreen(); w.setLocation(eventLocationOnScreen.x - dragOffsetX, eventLocationOnScreen.y - dragOffsetY); } else if (dragCursor != 0) { Rectangle r = w.getBounds(); Rectangle startBounds = new Rectangle(r); Dimension min = w.getMinimumSize(); switch (dragCursor) { case Cursor.E_RESIZE_CURSOR: adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0); break; case Cursor.S_RESIZE_CURSOR: adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height); break; case Cursor.N_RESIZE_CURSOR: adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY)); break; case Cursor.W_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0); break; case Cursor.NE_RESIZE_CURSOR: adjust( r, min, 0, pt.y - dragOffsetY, pt.x + (dragWidth - dragOffsetX) - r.width, -(pt.y - dragOffsetY)); break; case Cursor.SE_RESIZE_CURSOR: adjust( r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, pt.y + (dragHeight - dragOffsetY) - r.height); break; case Cursor.NW_RESIZE_CURSOR: adjust( r, min, pt.x - dragOffsetX, pt.y - dragOffsetY, -(pt.x - dragOffsetX), -(pt.y - dragOffsetY)); break; case Cursor.SW_RESIZE_CURSOR: adjust( r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), pt.y + (dragHeight - dragOffsetY) - r.height); break; default: break; } if (!r.equals(startBounds)) { w.setBounds(r); // Defer repaint/validate on mouseReleased unless dynamic // layout is active. if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) { w.validate(); getRootPane().repaint(); } } } }
Example 5
Source File: WindowUtils.java From gcs with Mozilla Public License 2.0 | 4 votes |
/** * Forces the specified window onscreen. * * @param window The window to force onscreen. */ public static void forceOnScreen(Window window) { Rectangle maxBounds = getMaximumWindowBounds(window); Rectangle bounds = window.getBounds(); Point location = new Point(bounds.x, bounds.y); Dimension size = window.getMinimumSize(); if (bounds.width < size.width) { bounds.width = size.width; } if (bounds.height < size.height) { bounds.height = size.height; } if (bounds.x < maxBounds.x) { bounds.x = maxBounds.x; } else if (bounds.x >= maxBounds.x + maxBounds.width) { bounds.x = maxBounds.x + maxBounds.width - 1; } if (bounds.x + bounds.width >= maxBounds.x + maxBounds.width) { bounds.x = maxBounds.x + maxBounds.width - bounds.width; if (bounds.x < maxBounds.x) { bounds.x = maxBounds.x; bounds.width = maxBounds.width; } } if (bounds.y < maxBounds.y) { bounds.y = maxBounds.y; } else if (bounds.y >= maxBounds.y + maxBounds.height) { bounds.y = maxBounds.y + maxBounds.height - 1; } if (bounds.y + bounds.height >= maxBounds.y + maxBounds.height) { bounds.y = maxBounds.y + maxBounds.height - bounds.height; if (bounds.y < maxBounds.y) { bounds.y = maxBounds.y; bounds.height = maxBounds.height; } } if (location.x != bounds.x || location.y != bounds.y) { window.setBounds(bounds); } else { window.setSize(bounds.width, bounds.height); } window.validate(); }
Example 6
Source File: TN5250jSplashScreen.java From tn5250j with GNU General Public License v2.0 | 4 votes |
/** * Creates the Splash screen window and configures it. */ protected void initialize(ImageIcon iimage) { image = iimage.getImage(); // if no image, return if (image == null) { throw new IllegalArgumentException("Image specified is invalid."); } // System.out.println(" here in splash "); MediaTracker tracker = new MediaTracker(this); tracker.addImage(image,0); try { tracker.waitForAll(); } catch(Exception e) { System.out.println(e.getMessage()); } // create dialog window f = new Frame(); dialog = new Window(f); dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Dimension s = new Dimension(image.getWidth(this) + 2, image.getHeight(this) + 2); setSize(s); dialog.setLayout(new BorderLayout()); dialog.setSize(s); dialog.add(this,BorderLayout.CENTER); dialog.pack(); // position splash screen Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int x = (screen.width - s.width)/2; if (x < 0) { x = 0; } int y = (screen.height - s.height)/2; if (y < 0) { y = 0; } dialog.setLocation(x, y); dialog.validate(); }
Example 7
Source File: RPSplash.java From RipplePower with Apache License 2.0 | 4 votes |
public RPSplash(Color progressBarColour, String imageResourcePath, String buildString, Color buildTextColour, int buildLabelX, int buildLabelY, String versionNumber, Color versionTextColour, int versionLabelX, int versionLabelY, boolean autonClose, final Updateable update) { this.buildTextColour = buildTextColour; this.buildLabelX = buildLabelX; this.buildLabelY = buildLabelY; this.versionTextColour = versionTextColour; this.versionLabelX = versionLabelX; this.versionLabelY = versionLabelY; progressColour = progressBarColour; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); setBackground(Color.white); gradientColour = UIRes.getBrighter(progressBarColour, 0.75); Font font = new Font(Font.SANS_SERIF, Font.PLAIN, 11); setFont(font); fontMetrics = getFontMetrics(font); image = LImage.createImage(imageResourcePath).getBufferedImage(); if (buildString != null) { build = buildString; } if (versionNumber != null) { version = versionNumber; } Dimension size = new Dimension(image.getWidth(this), image.getHeight(this)); window = new Window(new Frame()); window.setSize(size); window.setLayout(new BorderLayout()); window.add(BorderLayout.CENTER, this); window.setLocation(UIRes.getPointToCenter(window, size)); window.validate(); window.setVisible(true); if (autonClose) { Updateable call = new Updateable() { @Override public void action(Object o) { for (; progress < 10;) { process(); try { Thread.sleep(100); } catch (InterruptedException e) { } } RPSplash.this.dispose(); if (update != null) { update.action(progress); } } }; LSystem.postThread(call); } }
Example 8
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 4 votes |
private void setSizeAndDimensions(@NotNull JTable table, @NotNull JBPopup popup, @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) { JComponent content = popup.getContent(); Window window = SwingUtilities.windowForComponent(content); Dimension d = window.getSize(); int width = calcMaxWidth(table); width = (int) Math.max(d.getWidth(), width); Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize(); width = Math.max((int) headerSize.getWidth(), width); width = Math.max(myWidth, width); if (myWidth == -1) myWidth = width; int newWidth = Math.max(width, d.width + width - myWidth); myWidth = newWidth; int rowsToShow = Math.min(30, data.size()); Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow); Rectangle rectangle = fitToScreen(dimension, popupPosition, table); dimension = rectangle.getSize(); Point location = window.getLocation(); if (!location.equals(rectangle.getLocation())) { window.setLocation(rectangle.getLocation()); } if (!data.isEmpty()) { TableScrollingUtil.ensureSelectionExists(table); } table.setSize(dimension); //table.setPreferredSize(dimension); //table.setMaximumSize(dimension); //table.setPreferredScrollableViewportSize(dimension); Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize(); int newHeight = (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4/* invisible borders, margins etc*/; Dimension newDim = new Dimension(dimension.width, newHeight); window.setSize(newDim); window.setMinimumSize(newDim); window.setMaximumSize(newDim); window.validate(); window.repaint(); table.revalidate(); table.repaint(); }
Example 9
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 4 votes |
private void setSizeAndDimensions(@NotNull JTable table, @NotNull JBPopup popup, @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) { JComponent content = popup.getContent(); Window window = SwingUtilities.windowForComponent(content); Dimension d = window.getSize(); int width = calcMaxWidth(table); width = (int)Math.max(d.getWidth(), width); Dimension headerSize = ((AbstractPopup)popup).getHeaderPreferredSize(); width = Math.max((int)headerSize.getWidth(), width); width = Math.max(myWidth, width); if (myWidth == -1) myWidth = width; int newWidth = Math.max(width, d.width + width - myWidth); myWidth = newWidth; int rowsToShow = Math.min(30, data.size()); Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow); Rectangle rectangle = fitToScreen(dimension, popupPosition, table); dimension = rectangle.getSize(); Point location = window.getLocation(); if (!location.equals(rectangle.getLocation())) { window.setLocation(rectangle.getLocation()); } if (!data.isEmpty()) { TableScrollingUtil.ensureSelectionExists(table); } table.setSize(dimension); //table.setPreferredSize(dimension); //table.setMaximumSize(dimension); //table.setPreferredScrollableViewportSize(dimension); Dimension footerSize = ((AbstractPopup)popup).getFooterPreferredSize(); int newHeight = (int)(dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4/* invisible borders, margins etc*/; Dimension newDim = new Dimension(dimension.width, newHeight); window.setSize(newDim); window.setMinimumSize(newDim); window.setMaximumSize(newDim); window.validate(); window.repaint(); table.revalidate(); table.repaint(); }
Example 10
Source File: WindowMouseHandler.java From littleluck with Apache License 2.0 | 2 votes |
public void updateBound(Point pt, Window w) { Rectangle r = w.getBounds(); Rectangle startBounds = new Rectangle(r); Dimension min = w.getMinimumSize(); switch (dragCursor) { case Cursor.E_RESIZE_CURSOR: adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0); break; case Cursor.S_RESIZE_CURSOR: adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height); break; case Cursor.N_RESIZE_CURSOR: adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY)); break; case Cursor.W_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0); break; case Cursor.NE_RESIZE_CURSOR: adjust(r, min, 0, pt.y - dragOffsetY, pt.x + (dragWidth - dragOffsetX) - r.width, -(pt.y - dragOffsetY)); break; case Cursor.SE_RESIZE_CURSOR: adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, pt.y + (dragHeight - dragOffsetY) - r.height); break; case Cursor.NW_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, pt.y - dragOffsetY, -(pt.x - dragOffsetX), -(pt.y - dragOffsetY)); break; case Cursor.SW_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), pt.y + (dragHeight - dragOffsetY) - r.height); break; default: break; } if(!r.equals(startBounds)) { w.setBounds(r); if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) { w.validate(); w.repaint(); } } }