Java Code Examples for javax.swing.border.Border#getBorderInsets()

The following examples show how to use javax.swing.border.Border#getBorderInsets() . 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: DefaultCheckListCellRenderer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Component getListCellRendererComponent(JList list, Object value,
    int index, boolean isSelected, boolean cellHasFocus) {
    setComponentOrientation(list.getComponentOrientation());
    if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    }
    else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }

    setEnabled(list.isEnabled());
    setFont(list.getFont());
    if( cellHasFocus ) {
        Border b = UIManager.getBorder("List.focusCellHighlightBorder"); //NOI18N
        if( null != b && null != b.getBorderInsets(this) )
            setBorder( b );
    } else {
        setBorder( noFocusBorder);
    }

    setText((value == null) ? "" : value.toString());
    setSelected(((CheckListModel) list.getModel()).isChecked(index));
    return this;
}
 
Example 2
Source File: UrlLabel.java    From binnavi with Apache License 2.0 6 votes vote down vote up
@Override
public void paint(final Graphics g) {
  super.paint(g);

  final Border border = getBorder();

  int realLeft = 0;
  int realWidth = getWidth();

  if (border != null) {
    final Insets insets = border.getBorderInsets(this);

    realWidth -= insets.right;
    realWidth -= insets.left;
    realLeft += insets.left;
  }

  g.drawLine(realLeft, getHeight() - 2, realWidth, getHeight() - 2);
}
 
Example 3
Source File: Test6657026.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static void test(Border border) {
    Insets actual = border.getBorderInsets(null);
    if (NEGATIVE.equals(actual)) {
        throw new Error("unexpected insets in " + border.getClass());
    }
    Insets expected = (Insets) actual.clone();
    // modify
    actual.top++;
    actual.left++;
    actual.right++;
    actual.bottom++;
    // validate
    if (!expected.equals(border.getBorderInsets(null))) {
        throw new Error("shared insets in " + border.getClass());
    }
}
 
Example 4
Source File: Test6657026.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void test(Border border) {
    Insets actual = border.getBorderInsets(null);
    if (NEGATIVE.equals(actual)) {
        throw new Error("unexpected insets in " + border.getClass());
    }
    Insets expected = (Insets) actual.clone();
    // modify
    actual.top++;
    actual.left++;
    actual.right++;
    actual.bottom++;
    // validate
    if (!expected.equals(border.getBorderInsets(null))) {
        throw new Error("shared insets in " + border.getClass());
    }
}
 
Example 5
Source File: Test6978482.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Component c = new Component() {};
    c.setBackground(Color.WHITE);
    c.setForeground(Color.BLACK);
    Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
    g.setClip(0, 0, 1024, 768);
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        border.getBorderInsets(c);
        border.paintBorder(c, g, 0, 0, 1024, 768);
    }
}
 
Example 6
Source File: AquaCaret.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Damages the area surrounding the caret to cause
 * it to be repainted in a new location.  If paint()
 * is reimplemented, this method should also be
 * reimplemented.  This method should update the
 * caret bounds (x, y, width, and height).
 *
 * @param r  the current location of the caret
 * @see #paint
 */
protected synchronized void damage(final Rectangle r) {
    if (r == null || fPainting) return;

    x = r.x - 4;
    y = r.y;
    width = 10;
    height = r.height;

    // Don't damage the border area.  We can't paint a partial border, so get the
    // intersection of the caret rectangle and the component less the border, if any.
    final Rectangle caretRect = new Rectangle(x, y, width, height);
    final Border border = getComponent().getBorder();
    if (border != null) {
        final Rectangle alloc = getComponent().getBounds();
        alloc.x = alloc.y = 0;
        final Insets borderInsets = border.getBorderInsets(getComponent());
        alloc.x += borderInsets.left;
        alloc.y += borderInsets.top;
        alloc.width -= borderInsets.left + borderInsets.right;
        alloc.height -= borderInsets.top + borderInsets.bottom;
        Rectangle2D.intersect(caretRect, alloc, caretRect);
    }
    x = caretRect.x;
    y = caretRect.y;
    width = Math.max(caretRect.width, 1);
    height = Math.max(caretRect.height, 1);
    repaint();
}
 
Example 7
Source File: Test6978482.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Component c = new Component() {};
    c.setBackground(Color.WHITE);
    c.setForeground(Color.BLACK);
    Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
    g.setClip(0, 0, 1024, 768);
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        border.getBorderInsets(c);
        border.paintBorder(c, g, 0, 0, 1024, 768);
    }
}
 
Example 8
Source File: StyledSplitPaneUI.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Paint highlighted borders. Meanot to be used at mouseover.
 *
 * @param g graphics
 */
private void highLightBorder(Graphics g) {
	g.setColor(style.getHighLightColor());

	Border border = style.getBorder();
	if (orientation == JSplitPane.HORIZONTAL_SPLIT) {
		int width = border.getBorderInsets(this).left;
		g.fillRect(0, 0, width, getHeight());
		g.fillRect(getWidth() - width, 0, width, getHeight());
	} else {
		int height = border.getBorderInsets(this).top;
		g.fillRect(0, 0, getWidth(), height);
		g.fillRect(0, getHeight() - height, getWidth(), height);
	}
}
 
Example 9
Source File: DarculaPasswordFieldUI.java    From Darcula with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintBackground(Graphics graphics) {
  Graphics2D g = (Graphics2D)graphics;
  final JTextComponent c = getComponent();
  final Container parent = c.getParent();
  if (parent != null) {
    g.setColor(parent.getBackground());
    g.fillRect(0, 0, c.getWidth(), c.getHeight());
  }
  final Border border = c.getBorder();
  if (border instanceof DarculaTextBorder) {
    g.setColor(c.getBackground());
    final int width = c.getWidth();
    final int height = c.getHeight();
    final Insets i = border.getBorderInsets(c);
    if (c.hasFocus()) {
      final GraphicsConfig config = new GraphicsConfig(g);
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

      g.fillRoundRect(i.left - 5, i.top - 2, width - i.left - i.right + 10, height - i.top - i.bottom + 6, 5, 5);
      config.restore();
    }
    else {
      g.fillRect(i.left - 5, i.top - 2, width - i.left - i.right + 12, height - i.top - i.bottom + 6);
    }
  } else {
    super.paintBackground(g);
  }
}
 
Example 10
Source File: Test4856008.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void test(Border border, Insets insets) {
    Insets result = border.getBorderInsets(getComponent(border));
    if (insets == result) {
        throw new Error("both instances are the same for " + border.getClass());
    }
    if (!insets.equals(result)) {
        throw new Error("both insets are not equal for " + border.getClass());
    }
}
 
Example 11
Source File: Test6963870.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
void test(String uiName) {
    Border b = UIManager.getBorder(uiName);
    Insets i = b.getBorderInsets(null);
    if (i == null) {
        throw new RuntimeException("getBorderInsets() returns null for " + uiName);
    }
}
 
Example 12
Source File: Test4856008.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void test(Border border, Insets insets) {
    Insets result = border.getBorderInsets(getComponent(border));
    if (insets == result) {
        throw new Error("both instances are the same for " + border.getClass());
    }
    if (!insets.equals(result)) {
        throw new Error("both insets are not equal for " + border.getClass());
    }
}
 
Example 13
Source File: BasicSplitPaneDivider.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * If a border has been set on this component, returns the
 * border's insets, else calls super.getInsets.
 *
 * @return the value of the insets property.
 * @see #setBorder
 */
public Insets getInsets() {
    Border    border = getBorder();

    if (border != null) {
        return border.getBorderInsets(this);
    }
    return super.getInsets();
}
 
Example 14
Source File: Test6978482.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Component c = new Component() {};
    c.setBackground(Color.WHITE);
    c.setForeground(Color.BLACK);
    Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
    g.setClip(0, 0, 1024, 768);
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        border.getBorderInsets(c);
        border.paintBorder(c, g, 0, 0, 1024, 768);
    }
}
 
Example 15
Source File: ModernPasswordFieldUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintBackground(Graphics graphics) {
  Graphics2D g = (Graphics2D)graphics;
  final JTextComponent c = getComponent();
  final Container parent = c.getParent();
  if (parent != null) {
    g.setColor(parent.getBackground());
    g.fillRect(0, 0, c.getWidth(), c.getHeight());
  }
  final Border border = c.getBorder();
  if (border instanceof ModernTextBorder) {
    g.setColor(c.getBackground());
    final int width = c.getWidth();
    final int height = c.getHeight();
    final Insets i = border.getBorderInsets(c);
    if (c.hasFocus()) {
      final GraphicsConfig config = new GraphicsConfig(g);
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

      g.fillRect(i.left - 5, i.top - 2, width - i.left - i.right + 10, height - i.top - i.bottom + 6);
      config.restore();
    }
    else {
      g.fillRect(i.left - 5, i.top - 2, width - i.left - i.right + 12, height - i.top - i.bottom + 6);
    }
  }
  else {
    super.paintBackground(g);
  }
}
 
Example 16
Source File: AquaCaret.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Damages the area surrounding the caret to cause
 * it to be repainted in a new location.  If paint()
 * is reimplemented, this method should also be
 * reimplemented.  This method should update the
 * caret bounds (x, y, width, and height).
 *
 * @param r  the current location of the caret
 * @see #paint
 */
protected synchronized void damage(final Rectangle r) {
    if (r == null || fPainting) return;

    x = r.x - 4;
    y = r.y;
    width = 10;
    height = r.height;

    // Don't damage the border area.  We can't paint a partial border, so get the
    // intersection of the caret rectangle and the component less the border, if any.
    final Rectangle caretRect = new Rectangle(x, y, width, height);
    final Border border = getComponent().getBorder();
    if (border != null) {
        final Rectangle alloc = getComponent().getBounds();
        alloc.x = alloc.y = 0;
        final Insets borderInsets = border.getBorderInsets(getComponent());
        alloc.x += borderInsets.left;
        alloc.y += borderInsets.top;
        alloc.width -= borderInsets.left + borderInsets.right;
        alloc.height -= borderInsets.top + borderInsets.bottom;
        Rectangle2D.intersect(caretRect, alloc, caretRect);
    }
    x = caretRect.x;
    y = caretRect.y;
    width = Math.max(caretRect.width, 1);
    height = Math.max(caretRect.height, 1);
    repaint();
}
 
Example 17
Source File: Test6963870.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
void test(String uiName) {
    Border b = UIManager.getBorder(uiName);
    Insets i = b.getBorderInsets(null);
    if (i == null) {
        throw new RuntimeException("getBorderInsets() returns null for " + uiName);
    }
}
 
Example 18
Source File: BasicComboPopup.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Calculate the placement and size of the popup portion of the combo box based
 * on the combo box location and the enclosing screen bounds. If
 * no transformations are required, then the returned rectangle will
 * have the same values as the parameters.
 *
 * @param px starting x location
 * @param py starting y location
 * @param pw starting width
 * @param ph starting height
 * @return a rectangle which represents the placement and size of the popup
 */
protected Rectangle computePopupBounds(int px,int py,int pw,int ph) {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Rectangle screenBounds;

    // Calculate the desktop dimensions relative to the combo box.
    GraphicsConfiguration gc = comboBox.getGraphicsConfiguration();
    Point p = new Point();
    SwingUtilities.convertPointFromScreen(p, comboBox);
    if (gc != null) {
        Insets screenInsets = toolkit.getScreenInsets(gc);
        screenBounds = gc.getBounds();
        screenBounds.width -= (screenInsets.left + screenInsets.right);
        screenBounds.height -= (screenInsets.top + screenInsets.bottom);
        screenBounds.x += (p.x + screenInsets.left);
        screenBounds.y += (p.y + screenInsets.top);
    }
    else {
        screenBounds = new Rectangle(p, toolkit.getScreenSize());
    }
    int borderHeight = 0;
    Border popupBorder = getBorder();
    if (popupBorder != null) {
        Insets borderInsets = popupBorder.getBorderInsets(this);
        borderHeight = borderInsets.top + borderInsets.bottom;
        screenBounds.width -= (borderInsets.left + borderInsets.right);
        screenBounds.height -= borderHeight;
    }
    Rectangle rect = new Rectangle(px, py, pw, ph);
    if (py + ph > screenBounds.y + screenBounds.height) {
        if (ph <= -screenBounds.y - borderHeight) {
            // popup goes above
            rect.y = -ph - borderHeight;
        } else {
            // a full screen height popup
            rect.y = screenBounds.y + Math.max(0, (screenBounds.height - ph) / 2 );
            rect.height = Math.min(screenBounds.height, ph);
        }
    }
    return rect;
}
 
Example 19
Source File: ControlGridLayout.java    From pumpernickel with MIT License 4 votes vote down vote up
private Map<Component, Rectangle> createBlueprint(Container parent) {
	CellLayout masterLayout;
	if (group.contains(parent)) {
		masterLayout = new CellLayout();
		for (Container container : group) {
			if (container.isVisible()) {
				CellLayout cellLayout = getCellLayout(container);
				masterLayout.add(cellLayout);
			}
		}
	} else {
		masterLayout = getCellLayout(parent);
	}

	int x = 0;
	int y = 0;
	if (parent instanceof JComponent) {
		Border b = ((JComponent) parent).getBorder();
		if (b != null) {
			Insets i = b.getBorderInsets(parent);
			x = i.left;
			y = i.top;
		}
	}

	List<List<Component>> grid = createGrid(parent);

	Map<Component, Rectangle> returnValue = new HashMap<>();
	int y0 = y;
	for (int row = 0; row < grid.size(); row++) {
		int x0 = x;
		for (int column = 0; column < grid.get(row).size(); column++) {
			Component c = grid.get(row).get(column);
			Dimension d = c.getPreferredSize();
			Rectangle r = new Rectangle(x0, y0, d.width, d.height);
			// masterLayout.columnWidths[column],
			// masterLayout.rowHeights[row]);
			returnValue.put(c, r);

			x0 += masterLayout.columnWidths[column];
			x0 += horizontalPadding;
		}
		y0 += masterLayout.rowHeights[row];
		y0 += verticalPadding;
	}

	return returnValue;
}
 
Example 20
Source File: ConnectionsCustomizer.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private static Border emptyBorder(Border border) {
    Insets i = border == null ? null : border.getBorderInsets(new JTextField());
    return i == null ? BorderFactory.createEmptyBorder() :
           BorderFactory.createEmptyBorder(i.top, i.left, i.bottom, i.right);
}