Java Code Examples for java.awt.Window#pack()
The following examples show how to use
java.awt.Window#pack() .
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: Util.java From beanshell with Apache License 2.0 | 6 votes |
public static void startSplashScreen() { int width=275,height=148; Window win=new Window( new Frame() ); win.pack(); BshCanvas can=new BshCanvas(); can.setSize( width, height ); // why is this necessary? Toolkit tk=Toolkit.getDefaultToolkit(); Dimension dim=tk.getScreenSize(); win.setBounds( dim.width/2-width/2, dim.height/2-height/2, width, height ); win.add("Center", can); Image img=tk.getImage( Interpreter.class.getResource("/bsh/util/lib/splash.gif") ); MediaTracker mt=new MediaTracker(can); mt.addImage(img,0); try { mt.waitForAll(); } catch ( Exception e ) { } Graphics gr=can.getBufferedGraphics(); gr.drawImage(img, 0, 0, can); win.setVisible(true); win.toFront(); splashScreen = win; }
Example 2
Source File: WindowUtils.java From gcs with Mozilla Public License 2.0 | 6 votes |
public static void packAndCenterWindowOn(Window window, Component centeredOn) { window.pack(); Dimension prefSize = window.getPreferredSize(); Dimension minSize = window.getMinimumSize(); int width = Math.max(prefSize.width, minSize.width); int height = Math.max(prefSize.height, minSize.height); int x; int y; if (centeredOn != null) { Point where = centeredOn.getLocationOnScreen(); Dimension size = centeredOn.getSize(); x = where.x + (size.width - width) / 2; y = where.y + (size.height - height) / 2; } else { Rectangle bounds = getMaximumWindowBounds(window); x = bounds.x + (bounds.width - width) / 2; y = bounds.y + (bounds.height - height) / 2; } window.setLocation(x, y); forceOnScreen(window); }
Example 3
Source File: BasicSaveLocationPaneUI.java From pumpernickel with MIT License | 6 votes |
protected void repackIfNecessary() { Window window = SwingUtilities.getWindowAncestor(locationPane); if (window == null) return; window.pack(); // TODO: make this a little smarter /* * if(isExpanded()==false) { window.pack(); return; } * * Dimension realSize = locationPane.getSize(); Dimension preferredSize * = locationPane.getPreferredSize(); * * if(realSize.height<preferredSize.height) { int deltaHeight = * preferredSize.height-realSize.height; Dimension d = window.getSize(); * d.height += deltaHeight; window.setSize(d); } */ }
Example 4
Source File: AutoResizingPanel.java From netbeans with Apache License 2.0 | 6 votes |
private void enlargeAsNecessary(int currentWidth, int currentHeight, int requestedWidth, int requestedHeight) { if ((currentWidth >= requestedWidth) && (currentHeight >= requestedHeight)) { /* the panel is large enough */ return; } Window window = SwingUtilities.getWindowAncestor(this); if (window == null) { return; } try { requestedSize = new Dimension(requestedWidth, requestedHeight); window.pack(); } finally { requestedSize = null; } }
Example 5
Source File: RepositorySelectorBuilder.java From netbeans with Apache License 2.0 | 6 votes |
private void expandWindowToFitNewConnectorForm() { Window window = SwingUtilities.getWindowAncestor(this); if (window == null) { return; } Dimension currSize = getSize(); Dimension prefSize = getPreferredSize(); if ((currSize.width >= prefSize.width) && (currSize.height >= prefSize.height)) { /* the dialog is large enough to fit the form */ return; } try { requestedSize = new Dimension( Math.max(currSize.width, prefSize.width), Math.max(currSize.height, prefSize.height)); window.pack(); } finally { requestedSize = null; } }
Example 6
Source File: ClassOptionSelectionPanel.java From moa with GNU General Public License v3.0 | 6 votes |
public void classChoiceChanged(Object chosen) { this.chosenObject = chosen; JComponent newChosenObjectEditor = null; if (this.chosenObject instanceof OptionHandler) { OptionHandler chosenOptionHandler = (OptionHandler) this.chosenObject; newChosenObjectEditor = new OptionsConfigurationPanel( chosenOptionHandler.getPurposeString(), chosenOptionHandler.getOptions()); } if (this.chosenObjectEditor != null) { remove(this.chosenObjectEditor); } this.chosenObjectEditor = newChosenObjectEditor; if (this.chosenObjectEditor != null) { add(this.chosenObjectEditor, BorderLayout.CENTER); } Component component = this; while ((component != null) && !(component instanceof JDialog)) { component = component.getParent(); } if (component != null) { Window window = (Window) component; window.pack(); } }
Example 7
Source File: Sage.java From sagetv with Apache License 2.0 | 5 votes |
private static void splashAndLicense() { splashWindow = new Window(masterWindow); splashWindow.setLayout(new BorderLayout()); Image theImage = null; String splashImageName; if (Sage.get("ui/splash_image", null) != null) { theImage = Toolkit.getDefaultToolkit().createImage(Sage.get("ui/splash_image", null)); ImageUtils.ensureImageIsLoaded(theImage); } else { theImage = ImageUtils.fullyLoadImage(isTrueClient() ? (is64BitJVM() ? "images/splashclient64.gif" : "images/splashclient.gif") : (is64BitJVM() ? "images/splash64.gif" : "images/splash.gif" )); } ActiveImage splashImage = new ActiveImage(theImage); splashWindow.add(splashImage, "Center"); splashText = new Label(Sage.rez("Module_Init", new Object[] { "Application" }), Label.CENTER) { public void paint(Graphics g) { super.paint(g); g.setColor(Color.black); g.drawRect(0, 0, getWidth()-1, getHeight()-1); } }; splashText.setBackground(new Color(42, 103, 190)); splashText.setForeground(Color.white); splashWindow.add(splashText, "South"); Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize(); splashWindow.pack(); Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); splashWindow.setLocation(center.x - splashWindow.getWidth()/2, center.y - splashWindow.getHeight()/2); splashWindow.setVisible(true); }
Example 8
Source File: Test4759934.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private void show(Window window, String command) { JButton button = new JButton(command); button.setActionCommand(command); button.addActionListener(this); button.setFont(button.getFont().deriveFont(64.0f)); window.add(button); window.pack(); window.setVisible(true); }
Example 9
Source File: Test4759934.java From hottub with GNU General Public License v2.0 | 5 votes |
private void show(Window window, String command) { JButton button = new JButton(command); button.setActionCommand(command); button.addActionListener(this); button.setFont(button.getFont().deriveFont(64.0f)); window.add(button); window.pack(); window.setVisible(true); }
Example 10
Source File: Test4759934.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private void show(Window window, String command) { JButton button = new JButton(command); button.setActionCommand(command); button.addActionListener(this); button.setFont(button.getFont().deriveFont(64.0f)); window.add(button); window.pack(); window.setVisible(true); }
Example 11
Source File: SwingUtils.java From RipplePower with Apache License 2.0 | 5 votes |
public static void packLater(final Window win, final Component parent) { win.pack(); win.setLocationRelativeTo(parent); win.addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { win.pack(); win.setLocationRelativeTo(parent); } }); }
Example 12
Source File: DialogLoggerUtil.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
/** * Center on parent ( absolute true/false (exact center or 25% upper left) ) * * @param child * @param absolute */ public static void centerOnParent(final Window child, final boolean absolute) { child.pack(); boolean useChildsOwner = child.getOwner() != null ? ((child.getOwner() instanceof JFrame) || (child.getOwner() instanceof JDialog)) : false; final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); final Dimension parentSize = useChildsOwner ? child.getOwner().getSize() : screenSize; final Point parentLocationOnScreen = useChildsOwner ? child.getOwner().getLocationOnScreen() : new Point(0, 0); final Dimension childSize = child.getSize(); childSize.width = Math.min(childSize.width, screenSize.width); childSize.height = Math.min(childSize.height, screenSize.height); child.setSize(childSize); int x; int y; if ((child.getOwner() != null) && child.getOwner().isShowing()) { x = (parentSize.width - childSize.width) / 2; y = (parentSize.height - childSize.height) / 2; x += parentLocationOnScreen.x; y += parentLocationOnScreen.y; } else { x = (screenSize.width - childSize.width) / 2; y = (screenSize.height - childSize.height) / 2; } if (!absolute) { x /= 2; y /= 2; } child.setLocation(x, y); }
Example 13
Source File: Test4759934.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private void show(Window window, String command) { JButton button = new JButton(command); button.setActionCommand(command); button.addActionListener(this); button.setFont(button.getFont().deriveFont(64.0f)); window.add(button); window.pack(); window.setVisible(true); }
Example 14
Source File: Test4759934.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private void show(Window window, String command) { JButton button = new JButton(command); button.setActionCommand(command); button.addActionListener(this); button.setFont(button.getFont().deriveFont(64.0f)); window.add(button); window.pack(); window.setVisible(true); }
Example 15
Source File: Test4759934.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private void show(Window window, String command) { JButton button = new JButton(command); button.setActionCommand(command); button.addActionListener(this); button.setFont(button.getFont().deriveFont(64.0f)); window.add(button); window.pack(); window.setVisible(true); }
Example 16
Source File: ConnectPanel.java From netbeans with Apache License 2.0 | 5 votes |
/** * Refreshes panel with options corresponding to the selected connector type. * This method is called when a user selects new connector type. */ @Override public void actionPerformed (ActionEvent e) { int selectedIndex = ((JComboBox) e.getSource ()).getSelectedIndex (); refresh (selectedIndex, Properties.getDefault ().getProperties ("debugger")); Window w = SwingUtilities.getWindowAncestor(this); if (w != null) { w.pack (); // ugly hack... } }
Example 17
Source File: Test4759934.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void show(Window window, String command) { JButton button = new JButton(command); button.setActionCommand(command); button.addActionListener(this); button.setFont(button.getFont().deriveFont(64.0f)); window.add(button); window.pack(); window.setVisible(true); }
Example 18
Source File: PreferencePanel.java From pumpernickel with MIT License | 5 votes |
private void repack() { contents.animateStates(layoutRunnable); Window w = SwingUtilities.getWindowAncestor(this); if (w != null) { // TODO: this feature never really got off the ground, nor was it // essential. // if(animateResizing) { // contents.resizeWindow(); // } else { w.pack(); // } } }
Example 19
Source File: Test4759934.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private void show(Window window, String command) { JButton button = new JButton(command); button.setActionCommand(command); button.addActionListener(this); button.setFont(button.getFont().deriveFont(64.0f)); window.add(button); window.pack(); window.setVisible(true); }
Example 20
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(); }