下面列出了javax.swing.border.Border#paintBorder ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static void printBorder(PrintWriter html, Border border) {
Insets insets = border.getBorderInsets(new JToolBar());
html.println("<td>Border Insets(" + insets.top + "," + insets.left + "," + insets.bottom + "," + insets.right
+ ")</pre></td>");
int w = 50 + insets.left + insets.right;
int h = 20 + insets.top + insets.bottom;
try {
BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = img.createGraphics();
Composite old = g2.getComposite();
g2.setComposite(AlphaComposite.Clear);
g2.fillRect(0, 0, w, h);
g2.setComposite(old);
g2.setColor(Color.RED);
g2.fillRect(insets.left, insets.top, 49, 19);
border.paintBorder(null, g2, 0, 0, w, h);
g2.dispose();
html.println("<td>" + saveImage(img) + "</td>");
} catch (Exception e) {
// e.printStackTrace();
html.println("<td>NPE </td>");
}
}
@Override
protected void paintBorder(Graphics g) {
Border buttonBorder = getBorder();
if (buttonBorder == null) {
return;
}
Insets borderInsets = buttonBorder.getBorderInsets(this);
int leftIconWidth = primaryIcon.getIconWidth() + (borderInsets.left + borderInsets.right);
if (iconBorderEnabled) {
buttonBorder.paintBorder(this, g, 0, 0, leftIconWidth, getHeight());
}
int rightButtonWidth =
ARROW_WIDTH + ARROW_PADDING + (borderInsets.left + borderInsets.right);
buttonBorder.paintBorder(this, g, leftIconWidth, 0, rightButtonWidth, getHeight());
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = Utils.prepareGraphics( g );
if( showBorder && !Utils.isDefaultButtons() ) {
Border b = underline ? mouseoverBorder : regularBorder;
b.paintBorder(this, g, 0, 0, getWidth(), getHeight());
}
super.paintComponent(g2);
if( showBorder && Utils.isDefaultButtons() )
return;
Dimension size = getSize();
if( hasFocus() && isEnabled() ) {
g2.setStroke( LINK_IN_FOCUS_STROKE );
g2.setColor( Utils.getFocusedLinkColor() );
g2.drawRect( 0, 0, size.width - 1, size.height - 1 );
}
}
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);
}
}
@Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
// if menu bar is embedded, paint menu bar border
Border menuBarBorder = getMenuBarBorder();
if( menuBarBorder != null )
menuBarBorder.paintBorder( c, g, x, y, width, height );
if( hasJBRCustomDecoration() )
JBRWindowTopBorder.getInstance().paintBorder( c, g, x, y, width, height );
}
/**
* Paints the divider.
*/
public void paint(Graphics g) {
super.paint(g);
// Paint the border.
Border border = getBorder();
if (border != null) {
Dimension size = getSize();
border.paintBorder(this, g, 0, 0, size.width, size.height);
}
}
/**
* Paints the divider.
*/
public void paint(Graphics g) {
super.paint(g);
// Paint the border.
Border border = getBorder();
if (border != null) {
Dimension size = getSize();
border.paintBorder(this, g, 0, 0, size.width, size.height);
}
}
/**
* Paints the divider.
*/
public void paint(Graphics g) {
super.paint(g);
// Paint the border.
Border border = getBorder();
if (border != null) {
Dimension size = getSize();
border.paintBorder(this, g, 0, 0, size.width, size.height);
}
}
protected void paint(SynthContext context, Graphics g) {
Border vpBorder = scrollpane.getViewportBorder();
if (vpBorder != null) {
Rectangle r = scrollpane.getViewportBorderBounds();
vpBorder.paintBorder(scrollpane, g, r.x, r.y, r.width, r.height);
}
}
/**
* Paints the divider.
*/
public void paint(Graphics g) {
super.paint(g);
// Paint the border.
Border border = getBorder();
if (border != null) {
Dimension size = getSize();
border.paintBorder(this, g, 0, 0, size.width, size.height);
}
}
/**
* Paints the divider.
*/
public void paint(Graphics g) {
super.paint(g);
// Paint the border.
Border border = getBorder();
if (border != null) {
Dimension size = getSize();
border.paintBorder(this, g, 0, 0, size.width, size.height);
}
}
@Override
public void paint(Graphics g, JComponent c) {
super.paint(g, c);
final Border border = spinner.getBorder();
if (border != null) {
border.paintBorder(c, g, 0, 0, spinner.getWidth(), spinner.getHeight());
}
}
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);
}
}
/**
* Paints the divider.
*/
public void paint(Graphics g) {
super.paint(g);
// Paint the border.
Border border = getBorder();
if (border != null) {
Dimension size = getSize();
border.paintBorder(this, g, 0, 0, size.width, size.height);
}
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// if the item was selected, then paint the custom Mac selection background.
if (fIsSelected) {
Border backgroundPainter = fIsFocused
? UIManager.getBorder("List.sourceListFocusedSelectionBackgroundPainter")
: UIManager.getBorder("List.sourceListSelectionBackgroundPainter");
backgroundPainter.paintBorder(this, g, 0, 0, getWidth(), getHeight());
}
}
/**
* Paints the divider.
*/
public void paint(Graphics g) {
super.paint(g);
// Paint the border.
Border border = getBorder();
if (border != null) {
Dimension size = getSize();
border.paintBorder(this, g, 0, 0, size.width, size.height);
}
}
@Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Border border = getBorder();
String title = getTitle();
if (Objects.isNull(title) || title.isEmpty() || Objects.isNull(border)) {
super.paintBorder(c, g, x, y, width, height);
} else {
int edge = border instanceof TitledBorder ? 0 : EDGE_SPACING;
JLabel lbl = getTitleLabel(c);
Dimension size = lbl.getPreferredSize();
Insets insets = makeComponentBorderInsets(border, c, new Insets(0, 0, 0, 0));
int borderX = x + edge;
int borderY = y + edge;
int borderW = width - edge - edge;
int borderH = height - edge - edge;
int labelH = size.height;
int labelW = height - insets.top - insets.bottom; // TEST: - (edge * 8);
if (labelW > size.width) {
labelW = size.width;
}
int left = edge + insets.left / 2 - labelH / 2;
if (left < edge) {
borderX -= left;
borderW += left;
}
border.paintBorder(c, g, borderX, borderY, borderW, borderH);
Graphics2D g2 = (Graphics2D) g.create();
g2.translate(0, (height + labelW) / 2);
g2.rotate(Math.toRadians(-90));
// or: g2.transform(AffineTransform.getQuadrantRotateInstance(-1));
lbl.setSize(labelW, labelH);
lbl.paint(g2);
g2.dispose();
}
}
@Override
public void paint(Graphics g, JComponent c) {
super.paint(g, c);
final Border border = spinner.getBorder();
if (border != null) {
border.paintBorder(c, g, 0, 0, spinner.getWidth(), spinner.getHeight());
}
}
/**
* Paints the divider.
*/
public void paint(Graphics g) {
super.paint(g);
// Paint the border.
Border border = getBorder();
if (border != null) {
Dimension size = getSize();
border.paintBorder(this, g, 0, 0, size.width, size.height);
}
}
@Override
public void paint(Graphics g, JComponent c) {
Border vpBorder = scrollpane.getViewportBorder();
if (vpBorder != null) {
Rectangle r = scrollpane.getViewportBorderBounds();
vpBorder.paintBorder(scrollpane, g, r.x, r.y, r.width, r.height);
}
}