List of usage examples for java.awt Dimension clone
public Object clone()
From source file:Main.java
private static void setSizes(java.util.List<JComponent> aComponents, Dimension aDimension) { Iterator<JComponent> compsIter = aComponents.iterator(); while (compsIter.hasNext()) { JComponent comp = (JComponent) compsIter.next(); comp.setPreferredSize((Dimension) aDimension.clone()); comp.setMaximumSize((Dimension) aDimension.clone()); }/*from w ww.ja v a 2s . c om*/ }
From source file:net.java.sip.communicator.gui.AuthenticationSplash.java
private void registrationEqualizeButtonSizes() { JButton[] buttons = new JButton[] { cancelButton, registerButton }; String[] labels = new String[buttons.length]; for (int i = 0; i < labels.length; i++) { labels[i] = buttons[i].getText(); }/*from w ww . j a v a2s .co m*/ // Get the largest width and height int i = 0; Dimension maxSize = new Dimension(0, 0); Rectangle2D textBounds = null; Dimension textSize = null; FontMetrics metrics = buttons[0].getFontMetrics(buttons[0].getFont()); Graphics g = getGraphics(); for (i = 0; i < labels.length; ++i) { textBounds = metrics.getStringBounds(labels[i], g); maxSize.width = Math.max(maxSize.width, (int) textBounds.getWidth()); maxSize.height = Math.max(maxSize.height, (int) textBounds.getHeight()); } Insets insets = buttons[0].getBorder().getBorderInsets(buttons[0]); maxSize.width += insets.left + insets.right; maxSize.height += insets.top + insets.bottom; // reset preferred and maximum size since BoxLayout takes both // into account for (i = 0; i < buttons.length; ++i) { buttons[i].setPreferredSize((Dimension) maxSize.clone()); buttons[i].setMaximumSize((Dimension) maxSize.clone()); } }
From source file:net.java.sip.communicator.gui.AuthenticationSplash.java
/** * Sets the buttons along the bottom of the dialog to be the * same size. This is done dynamically by setting each button's * preferred and maximum sizes after the buttons are created. * This way, the layout automatically adjusts to the locale- * specific strings.// www. ja v a2s .c om */ private void equalizeButtonSizes() { JButton[] buttons = new JButton[] { loginButton, cancelButton, registerButton }; String[] labels = new String[buttons.length]; for (int i = 0; i < labels.length; i++) { labels[i] = buttons[i].getText(); } // Get the largest width and height int i = 0; Dimension maxSize = new Dimension(0, 0); Rectangle2D textBounds = null; Dimension textSize = null; FontMetrics metrics = buttons[0].getFontMetrics(buttons[0].getFont()); Graphics g = getGraphics(); for (i = 0; i < labels.length; ++i) { textBounds = metrics.getStringBounds(labels[i], g); maxSize.width = Math.max(maxSize.width, (int) textBounds.getWidth()); maxSize.height = Math.max(maxSize.height, (int) textBounds.getHeight()); } Insets insets = buttons[0].getBorder().getBorderInsets(buttons[0]); maxSize.width += insets.left + insets.right; maxSize.height += insets.top + insets.bottom; // reset preferred and maximum size since BoxLayout takes both // into account for (i = 0; i < buttons.length; ++i) { buttons[i].setPreferredSize((Dimension) maxSize.clone()); buttons[i].setMaximumSize((Dimension) maxSize.clone()); } }