List of usage examples for javax.swing.border Border getBorderInsets
Insets getBorderInsets(Component c);
From source file:Main.java
public static Insets getBorderInsetsForNoComponent(Border border) { // in java 7 calling getBorderInsets on TitleBorder with a null component throws NPE, // so let call that with a dummy component if (border instanceof TitledBorder) { return border.getBorderInsets(new Component() { });/* ww w. j a v a2 s. c o m*/ } return border.getBorderInsets(null); }
From source file:Main.java
/** * Return the preferred size of this component. * * @return the preferred size of this component. *//*from ww w . java 2 s . c o m*/ public Dimension getPreferredSize() { if (null == _prefSize) { // This was originaly done every time. // and the count of instantiated objects was amazing _prefSize = new Dimension(); _prefSize.height = 20; FontMetrics fm = getFontMetrics(getFont()); Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); _prefSize.width = fm.stringWidth(_fmt.format(cal.getTime())); Border border = getBorder(); if (border != null) { Insets ins = border.getBorderInsets(this); if (ins != null) { _prefSize.width += (ins.left + ins.right); } } Insets ins = getInsets(); if (ins != null) { _prefSize.width += (ins.left + ins.right) + 20; } } return _prefSize; }
From source file:org.zephyrsoft.util.gui.ImagePanel.java
private void calculateScaledImage() { Validate.notNull(image, "original image may not be null"); // use floats so division below won't round float imageWidth = image.getWidth(null); float imageHeight = image.getHeight(null); width = this.getWidth(); height = this.getHeight(); x = 0;//from www. j av a2 s. c om y = 0; // take special care for a border which might exist Border border = getBorder(); if (border != null) { x = border.getBorderInsets(this).left; y = border.getBorderInsets(this).top; width -= x; width -= border.getBorderInsets(this).right; height -= y; height -= border.getBorderInsets(this).bottom; } if (width < imageWidth || height < imageHeight) { // decide which value should be taken to rescale the image if ((width / height) > (imageWidth / imageHeight)) { imageWidth = -1; imageHeight = height; } else { imageWidth = width; imageHeight = -1; } // prevent errors if panel is 0 wide or high if (imageWidth == 0) { imageWidth = -1; } if (imageHeight == 0) { imageHeight = -1; } scaledImage = image.getScaledInstance(Float.valueOf(imageWidth).intValue(), Float.valueOf(imageHeight).intValue(), Image.SCALE_DEFAULT); } else { scaledImage = image; } }