javax.swing.JComponent#getInsets ( )源码实例Demo

下面列出了javax.swing.JComponent#getInsets ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FlatLaf   文件: FlatToolTipUI.java
@Override
public void paint( Graphics g, JComponent c ) {
	if( isMultiLine( c ) ) {
		FontMetrics fm = c.getFontMetrics( c.getFont() );
		Insets insets = c.getInsets();

		FlatUIUtils.setRenderingHints( (Graphics2D) g );
		g.setColor( c.getForeground() );

		List<String> lines = StringUtils.split( ((JToolTip)c).getTipText(), '\n' );

		int x = insets.left + 3;
		int x2 = c.getWidth() - insets.right - 3;
		int y = insets.top - fm.getDescent();
		int lineHeight = fm.getHeight();
		JComponent comp = ((JToolTip)c).getComponent();
		boolean leftToRight = (comp != null ? comp : c).getComponentOrientation().isLeftToRight();
		for( String line : lines ) {
			y += lineHeight;
			FlatUIUtils.drawString( c, g, line, leftToRight ? x : x2 - SwingUtilities.computeStringWidth( fm, line ), y );
		}
	} else
		super.paint( HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ), c );
}
 
源代码2 项目: openjdk-jdk9   文件: InsetsEncapsulation.java
void test(final JComponent component) {
    final Insets p = component.getInsets();
    p.top += 3;
    if (p.equals(component.getInsets())) {
        throw new RuntimeException("Insets altered by altering Insets!");
    }
}
 
源代码3 项目: jdk8u-jdk   文件: MotifScrollBarUI.java
public Dimension getPreferredSize(JComponent c) {
    Insets insets = c.getInsets();
    int dx = insets.left + insets.right;
    int dy = insets.top + insets.bottom;
    return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
        ? new Dimension(dx + 11, dy + 33)
        : new Dimension(dx + 33, dy + 11);
}
 
源代码4 项目: FlatLaf   文件: FlatScrollPaneUI.java
@Override
public void update( Graphics g, JComponent c ) {
	if( c.isOpaque() ) {
		FlatUIUtils.paintParentBackground( g, c );

		// paint background so that corners have same color as scroll bars
		Insets insets = c.getInsets();
		g.setColor( c.getBackground() );
		g.fillRect( insets.left, insets.top,
			c.getWidth() - insets.left - insets.right,
			c.getHeight() - insets.top - insets.bottom );
	}

	paint( g, c );
}
 
源代码5 项目: jdk8u_jdk   文件: MotifScrollBarUI.java
public Dimension getPreferredSize(JComponent c) {
    Insets insets = c.getInsets();
    int dx = insets.left + insets.right;
    int dy = insets.top + insets.bottom;
    return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
        ? new Dimension(dx + 11, dy + 33)
        : new Dimension(dx + 33, dy + 11);
}
 
源代码6 项目: jdk8u-dev-jdk   文件: MotifScrollBarUI.java
public Dimension getPreferredSize(JComponent c) {
    Insets insets = c.getInsets();
    int dx = insets.left + insets.right;
    int dy = insets.top + insets.bottom;
    return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
        ? new Dimension(dx + 11, dy + 33)
        : new Dimension(dx + 33, dy + 11);
}
 
源代码7 项目: dragonwell8_jdk   文件: MotifScrollBarUI.java
public Dimension getPreferredSize(JComponent c) {
    Insets insets = c.getInsets();
    int dx = insets.left + insets.right;
    int dy = insets.top + insets.bottom;
    return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
        ? new Dimension(dx + 11, dy + 33)
        : new Dimension(dx + 33, dy + 11);
}
 
源代码8 项目: netbeans   文件: MetalViewTabDisplayerUI.java
@Override
public Dimension getPreferredSize(JComponent c) {
    FontMetrics fm = getTxtFontMetrics();
    int height = fm == null ?
            21 : fm.getAscent() + 2 * fm.getDescent() + 4;
    Insets insets = c.getInsets();
    prefSize.height = height + insets.bottom + insets.top;
    return prefSize;
}
 
源代码9 项目: seaglass   文件: TextComponentPainter.java
/**
 * @param g
 * @param c
 * @param width
 * @param height
 */
private void paintLineSeparator(Graphics2D g, JComponent c, int width, int height) {
    g.setPaint(lineSeparatorEnabled);
    int lineYIncrement = g.getFontMetrics(c.getFont()).getHeight();
    int lineY = lineYIncrement+c.getInsets().top-1;
    while (lineY < height) {
        g.drawLine(c.getInsets().left, lineY, width-c.getInsets().right, lineY);
        lineY += lineYIncrement;
    }
}
 
源代码10 项目: jdk8u60   文件: InsetsEncapsulation.java
void test(final JComponent component) {
    final Insets p = component.getInsets();
    p.top += 3;
    if (p.equals(component.getInsets())) {
        throw new RuntimeException("Insets altered by altering Insets!");
    }
}
 
源代码11 项目: JDKSourceCode1.8   文件: MotifScrollBarUI.java
public Dimension getPreferredSize(JComponent c) {
    Insets insets = c.getInsets();
    int dx = insets.left + insets.right;
    int dy = insets.top + insets.bottom;
    return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
        ? new Dimension(dx + 11, dy + 33)
        : new Dimension(dx + 33, dy + 11);
}
 
源代码12 项目: openjdk-jdk9   文件: MotifScrollBarUI.java
public Dimension getPreferredSize(JComponent c) {
    Insets insets = c.getInsets();
    int dx = insets.left + insets.right;
    int dy = insets.top + insets.bottom;
    return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
        ? new Dimension(dx + 11, dy + 33)
        : new Dimension(dx + 33, dy + 11);
}
 
源代码13 项目: stendhal   文件: StyledButtonUI.java
@Override
public void paint(Graphics graphics, JComponent button) {
	paintBackground(graphics, button);

	// Restore normal look after pressing ends, if needed
	if (button instanceof AbstractButton) {
		ButtonModel model = ((AbstractButton) button).getModel();
		if (!model.isPressed()) {
			// Try to avoid switching borders if the button has none or custom
			// borders
			if (button.getBorder().equals(style.getBorderDown())) {
				button.setBorder(style.getBorder());
			}
		}
		if (model.isRollover()) {
			hilite(graphics, button);
		}

		if (button instanceof JButton) {
			if (((JButton) button).isDefaultButton()) {
				Insets insets = button.getInsets();
				graphics.setColor(style.getShadowColor());
				int width = button.getWidth() - insets.right - insets.left - 3;
				int height = button.getHeight() - insets.top - insets.bottom - 3;
				graphics.drawRect(insets.left + 1, insets.right + 1, width, height);
			}
		}
	}

	super.paint(graphics, button);
}
 
源代码14 项目: openjdk-jdk8u   文件: InsetsEncapsulation.java
void test(final JComponent component) {
    final Insets p = component.getInsets();
    p.top += 3;
    if (p.equals(component.getInsets())) {
        throw new RuntimeException("Insets altered by altering Insets!");
    }
}
 
源代码15 项目: jdk8u-jdk   文件: InsetsEncapsulation.java
void test(final JComponent component) {
    final Insets p = component.getInsets();
    p.top += 3;
    if (p.equals(component.getInsets())) {
        throw new RuntimeException("Insets altered by altering Insets!");
    }
}
 
源代码16 项目: PolyGlot   文件: PToolTipUI.java
@Override
public Dimension getPreferredSize(JComponent c) {
    FontMetrics fm = c.getFontMetrics(c.getFont());
    Insets insets = c.getInsets();

    Dimension prefSize = new Dimension(insets.left+insets.right,
                                       insets.top+insets.bottom);
    String text = ((JToolTip)c).getTipText();

    if (text != null && !text.isEmpty()) {
        prefSize.width += fm.stringWidth(text);
        prefSize.height += fm.getHeight();
    }
    return prefSize;
}
 
源代码17 项目: pumpernickel   文件: PaletteUI.java
@Override
public Dimension getMinimumSize(JComponent c) {
	JPalette p = (JPalette) c;
	int cellHeight = p.getCellHeight();
	int cellWidth = p.getCellWidth();
	Color[][] colors = p.getColors();
	int rowCount = colors.length;
	int columnCount = colors[0].length;
	Insets i = c.getInsets();
	return new Dimension(columnCount * cellWidth + i.left + i.right,
			rowCount * cellHeight + i.top + i.bottom);
}
 
源代码18 项目: rapidminer-studio   文件: ToggleButtonUI.java
@Override
public void paint(Graphics g, JComponent c) {
	AbstractButton b = (AbstractButton) c;

	Dimension size = b.getSize();
	FontMetrics fm = g.getFontMetrics();

	Insets i = c.getInsets();

	Rectangle viewRect = new Rectangle(size);

	viewRect.x += i.left;
	viewRect.y += i.top;
	viewRect.width -= i.right + viewRect.x;
	viewRect.height -= i.bottom + viewRect.y;

	Rectangle iconRect = new Rectangle();
	Rectangle textRect = new Rectangle();

	Font f = c.getFont();
	g.setFont(f);

	String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), b.getIcon(), b.getVerticalAlignment(),
			b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect,
			textRect, b.getText() == null ? 0 : b.getIconTextGap());

	g.setColor(b.getBackground());

	if (b.isContentAreaFilled()) {
		if (RapidLookTools.isToolbarButton(b)) {
			RapidLookTools.drawToolbarButton(g, b);
		} else {
			RapidLookTools.drawButton(b, g, RapidLookTools.createShapeForButton(b));
		}
	}

	if (b.getIcon() != null) {
		paintIcon(g, b, iconRect);
	}

	if (text != null && !text.equals("")) {
		View v = (View) c.getClientProperty(BasicHTML.propertyKey);
		if (v != null) {
			v.paint(g, textRect);
		} else {
			paintText(g, b, textRect, text);
		}
	}

	if (b.isFocusPainted() && b.hasFocus()) {
		paintFocus(g, b, viewRect, textRect, iconRect);
	}

	if (!RapidLookTools.isToolbarButton(b)) {
		if (b.isBorderPainted()) {
			RapidLookTools.drawButtonBorder(b, g, RapidLookTools.createBorderShapeForButton(b));
		}
	}
}
 
源代码19 项目: orbit-image-analysis   文件: BasicLinkButtonUI.java
public void paint(Graphics g, JComponent c) {
  AbstractButton b = (AbstractButton)c;
  ButtonModel model = b.getModel();

  FontMetrics fm = g.getFontMetrics();

  Insets i = c.getInsets();

  viewRect.x = i.left;
  viewRect.y = i.top;
  viewRect.width = b.getWidth() - (i.right + viewRect.x);
  viewRect.height = b.getHeight() - (i.bottom + viewRect.y);

  textRect.x = textRect.y = textRect.width = textRect.height = 0;
  iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;

  Font f = c.getFont();
  g.setFont(f);

  // layout the text and icon
  String text =
    SwingUtilities.layoutCompoundLabel(
      c,
      fm,
      b.getText(),
      b.getIcon(),
      b.getVerticalAlignment(),
      b.getHorizontalAlignment(),
      b.getVerticalTextPosition(),
      b.getHorizontalTextPosition(),
      viewRect,
      iconRect,
      textRect,
      b.getText() == null ? 0 : b.getIconTextGap());

  clearTextShiftOffset();

  // perform UI specific press action, e.g. Windows L&F shifts text
  if (model.isArmed() && model.isPressed()) {
    paintButtonPressed(g, b);
  }

  // Paint the Icon
  if (b.getIcon() != null) {
    paintIcon(g, c, iconRect);
  }

  Composite oldComposite = ((Graphics2D)g).getComposite();

  if (model.isRollover()) {
    ((Graphics2D)g).setComposite(
      AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
  }

  if (text != null && !text.equals("")) {
    View v = (View)c.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
      textRect.x += getTextShiftOffset();
      textRect.y += getTextShiftOffset();
      v.paint(g, textRect);
      textRect.x -= getTextShiftOffset();
      textRect.y -= getTextShiftOffset();
    } else {
      paintText(g, b, textRect, text);
    }
  }

  if (b.isFocusPainted() && b.hasFocus()) {
    // paint UI specific focus
    paintFocus(g, b, viewRect, textRect, iconRect);
  }

  ((Graphics2D)g).setComposite(oldComposite);
}
 
源代码20 项目: PolyGlot   文件: PToolTipUI.java
/**
 * To override font, override createToolTip() on component creating tooltip.
 * On creation of ToolTip, change to desired font.
 * @param g
 * @param c 
 */
@Override
public void paint(Graphics g, JComponent c) {
    String tipText = ((JToolTip)c).getTipText();
    tipText = tipText == null ? "" : tipText;
    String[] tipLines = tipText.split("\n");
    Font font = c.getFont();
    
    g.setFont(font);
    
    FontMetrics metrics = g.getFontMetrics();
    int fontHeight = metrics.getHeight();
    int height = (fontHeight * tipLines.length) + 2;
    int width = this.getWidestStringText(tipLines, metrics) + 10;
    
    int fontSize = font.getSize();
    fontSize = fontSize == 0 ? PGTUtil.DEFAULT_FONT_SIZE.intValue() : fontSize;
    c.setFont(font.deriveFont(fontSize));
    ((JToolTip)c).setTipText(tipText);
    
    
    Dimension size = new Dimension(width, height);
    
    c.setSize(size);
    c.getParent().setSize(size);
    
    Insets insets = c.getInsets();
    Rectangle paintTextR = new Rectangle(
        insets.left,
        insets.top,
        size.width - (insets.left + insets.right),
        size.height - (insets.top + insets.bottom));
    
    ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    
    g.setColor(Color.black);
    g.fillRect(insets.left,
        insets.top,
        size.width - (insets.left + insets.right),
        size.height - (insets.top + insets.bottom));
    
    g.setColor(Color.white);
    
    for (int i = 0 ; i < tipLines.length; i++) {
        g.drawString(tipLines[i], paintTextR.x + 5,
                paintTextR.y + metrics.getAscent() + (i * (fontHeight)));
    }
}