下面列出了javax.swing.JComponent#isOpaque ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected void paint(SeaGlassContext context, Graphics g) {
JComponent c = context.getComponent();
JViewport viewport = (JViewport) c;
if (c.isOpaque()) {
Component view = viewport.getView();
Object ui = (view == null) ? null : invokeGetter(view, "getUI", null);
if (ui instanceof ViewportPainter) {
((ViewportPainter) ui).paintViewport(context, g, viewport);
} else {
if (viewport.getView() != null) {
g.setColor(viewport.getView().getBackground());
g.fillRect(0, 0, c.getWidth(), c.getHeight());
}
}
}
}
@Override
public void paint(Graphics g, JComponent c) {
if (c.isOpaque()) {
ImageLibrary.drawTiledImage("image.background.FreeColToolTip",
g, c, null);
}
g.setColor(Color.BLACK); // FIXME: find out why this is necessary
Graphics2D graphics = (Graphics2D)g;
float x = margin;
float y = margin;
for (String line : lineBreak.split(((JToolTip) c).getTipText())) {
if (line.isEmpty()) {
y += LEADING;
continue;
}
AttributedCharacterIterator styledText =
new AttributedString(line).getIterator();
LineBreakMeasurer measurer = new LineBreakMeasurer(styledText, frc);
while (measurer.getPosition() < styledText.getEndIndex()) {
TextLayout layout = measurer.nextLayout(maximumWidth);
y += (layout.getAscent());
float dx = layout.isLeftToRight() ?
0 : (maximumWidth - layout.getAdvance());
layout.draw(graphics, x + dx, y);
y += layout.getDescent() + layout.getLeading();
}
}
}
private static void setOpaqueLayerRecursive(Component opaqueComponent) {
if (opaqueComponent instanceof JTextArea ||
opaqueComponent instanceof JLabel) {
if (opaqueComponent.isOpaque()) {
((JComponent) opaqueComponent).setOpaque(false);
}
} else if (opaqueComponent instanceof JPanel) {
JComponent panel = (JComponent)opaqueComponent;
if (panel.isOpaque()) {
panel.setOpaque(false);
}
iterateOverOpaqueLayersComponents(panel);
}
}
@Override
public final void update(final Graphics g, final JComponent c) {
if (c.isOpaque()) {
AquaUtils.fillRect(g, c);
}
paint(g, c);
}
@Override
public void update( Graphics g, JComponent c ) {
if( c.isOpaque() )
FlatUIUtils.paintParentBackground( g, c );
paint( g, c );
}
@Override
public void update( Graphics g, JComponent c ) {
Component view = ((JViewport)c).getView();
if( c.isOpaque() && view instanceof JTable ) {
// paint viewport background in same color as table background
g.setColor( view.getBackground() );
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
paint( g, c );
} else
super.update( g, c );
}
@Override
public final void update(final Graphics g, final JComponent c) {
if (c.isOpaque()) {
AquaUtils.fillRect(g, c);
}
paint(g, c);
}
@Override
public final void update(final Graphics g, final JComponent c) {
if (c.isOpaque()) {
AquaUtils.fillRect(g, c);
}
paint(g, c);
}
@Override
public final void update(final Graphics g, final JComponent c) {
if (c.isOpaque()) {
AquaUtils.fillRect(g, c);
}
paint(g, c);
}
protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) {
if (c.isOpaque()) {
DesktopPane panePainter = new DesktopPane();
panePainter.setDimension(new Dimension(width, height));
panePainter.paintIcon(c, g, 0, 0);
}
}
/**
* Overriden to paint the background of the component but keeping the rounded
* corners.
*/
public void update(Graphics g, JComponent c) {
if (c.isOpaque()) {
g.setColor(c.getParent().getBackground());
g.fillRect(0, 0, c.getWidth(), c.getHeight());
g.setColor(c.getBackground());
g.fillRect(0, ROUND_HEIGHT, c.getWidth(), c.getHeight() - ROUND_HEIGHT);
}
paint(g, c);
}
@Override
public void paintBackground(java.awt.Graphics g) {
JComponent c = getComponent();
if (c.isOpaque()) {
ImageLibrary.drawTiledImage("image.background.FreeColTextArea",
g, c, null);
}
}
private BufferedImage createContentImage( JComponent c, Dimension contentSize ) {
GraphicsConfiguration cfg = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration();
boolean opaque = c.isOpaque();
c.setOpaque(true);
BufferedImage res = cfg.createCompatibleImage(contentSize.width, contentSize.height);
Graphics2D g = res.createGraphics();
g.setColor( c.getBackground() );
g.fillRect(0, 0, contentSize.width, contentSize.height);
g.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f ));
c.paint(g);
c.setOpaque(opaque);
return res;
}
@Override
public void update( Graphics g, JComponent c ) {
float focusWidth = FlatUIUtils.getBorderFocusWidth( c );
float arc = FlatUIUtils.getBorderArc( c );
// fill background if opaque to avoid garbage if user sets opaque to true
if( c.isOpaque() && (focusWidth > 0 || arc > 0) )
FlatUIUtils.paintParentBackground( g, c );
Graphics2D g2 = (Graphics2D) g;
FlatUIUtils.setRenderingHints( g2 );
int width = c.getWidth();
int height = c.getHeight();
Component nextButton = getHandler().nextButton;
int arrowX = nextButton.getX();
int arrowWidth = nextButton.getWidth();
boolean paintButton = !"none".equals( buttonStyle );
boolean enabled = spinner.isEnabled();
boolean isLeftToRight = spinner.getComponentOrientation().isLeftToRight();
// paint background
g2.setColor( getBackground( enabled ) );
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
// paint arrow buttons background
if( paintButton && enabled ) {
g2.setColor( buttonBackground );
Shape oldClip = g2.getClip();
if( isLeftToRight )
g2.clipRect( arrowX, 0, width - arrowX, height );
else
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
g2.setClip( oldClip );
}
// paint vertical line between value and arrow buttons
if( paintButton ) {
g2.setColor( enabled ? borderColor : disabledBorderColor );
float lw = scale( 1f );
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - 1 - (focusWidth * 2) ) );
}
paint( g, c );
}
/**
* Notifies this UI delegate that it is time to paint the specified
* component. This method is invoked by <code>JComponent</code>
* when the specified component is being painted.
*
* <p>By default this method fills the specified component with
* its background color if its {@code opaque} property is {@code true},
* and then immediately calls {@code paint}. In general this method need
* not be overridden by subclasses; all look-and-feel rendering code should
* reside in the {@code paint} method.
*
* @param g the <code>Graphics</code> context in which to paint
* @param c the component being painted;
* this argument is often ignored,
* but might be used if the UI object is stateless
* and shared by multiple components
*
* @see #paint
* @see javax.swing.JComponent#paintComponent
*/
public void update(Graphics g, JComponent c) {
if (c.isOpaque()) {
g.setColor(c.getBackground());
g.fillRect(0, 0, c.getWidth(),c.getHeight());
}
paint(g, c);
}
/**
* Notifies this UI delegate that it is time to paint the specified
* component. This method is invoked by <code>JComponent</code>
* when the specified component is being painted.
*
* <p>By default this method fills the specified component with
* its background color if its {@code opaque} property is {@code true},
* and then immediately calls {@code paint}. In general this method need
* not be overridden by subclasses; all look-and-feel rendering code should
* reside in the {@code paint} method.
*
* @param g the <code>Graphics</code> context in which to paint
* @param c the component being painted;
* this argument is often ignored,
* but might be used if the UI object is stateless
* and shared by multiple components
*
* @see #paint
* @see javax.swing.JComponent#paintComponent
*/
public void update(Graphics g, JComponent c) {
if (c.isOpaque()) {
g.setColor(c.getBackground());
g.fillRect(0, 0, c.getWidth(),c.getHeight());
}
paint(g, c);
}
/**
* Notifies this UI delegate that it is time to paint the specified
* component. This method is invoked by <code>JComponent</code>
* when the specified component is being painted.
*
* <p>By default this method fills the specified component with
* its background color if its {@code opaque} property is {@code true},
* and then immediately calls {@code paint}. In general this method need
* not be overridden by subclasses; all look-and-feel rendering code should
* reside in the {@code paint} method.
*
* @param g the <code>Graphics</code> context in which to paint
* @param c the component being painted;
* this argument is often ignored,
* but might be used if the UI object is stateless
* and shared by multiple components
*
* @see #paint
* @see javax.swing.JComponent#paintComponent
*/
public void update(Graphics g, JComponent c) {
if (c.isOpaque()) {
g.setColor(c.getBackground());
g.fillRect(0, 0, c.getWidth(),c.getHeight());
}
paint(g, c);
}
/**
* Notifies this UI delegate that it is time to paint the specified
* component. This method is invoked by <code>JComponent</code>
* when the specified component is being painted.
*
* <p>By default this method fills the specified component with
* its background color if its {@code opaque} property is {@code true},
* and then immediately calls {@code paint}. In general this method need
* not be overridden by subclasses; all look-and-feel rendering code should
* reside in the {@code paint} method.
*
* @param g the <code>Graphics</code> context in which to paint
* @param c the component being painted;
* this argument is often ignored,
* but might be used if the UI object is stateless
* and shared by multiple components
*
* @see #paint
* @see javax.swing.JComponent#paintComponent
*/
public void update(Graphics g, JComponent c) {
if (c.isOpaque()) {
g.setColor(c.getBackground());
g.fillRect(0, 0, c.getWidth(),c.getHeight());
}
paint(g, c);
}
/**
* Notifies this UI delegate that it is time to paint the specified
* component. This method is invoked by <code>JComponent</code>
* when the specified component is being painted.
*
* <p>By default this method fills the specified component with
* its background color if its {@code opaque} property is {@code true},
* and then immediately calls {@code paint}. In general this method need
* not be overridden by subclasses; all look-and-feel rendering code should
* reside in the {@code paint} method.
*
* @param g the <code>Graphics</code> context in which to paint
* @param c the component being painted;
* this argument is often ignored,
* but might be used if the UI object is stateless
* and shared by multiple components
*
* @see #paint
* @see javax.swing.JComponent#paintComponent
*/
public void update(Graphics g, JComponent c) {
if (c.isOpaque()) {
g.setColor(c.getBackground());
g.fillRect(0, 0, c.getWidth(),c.getHeight());
}
paint(g, c);
}
/**
* Notifies this UI delegate that it is time to paint the specified
* component. This method is invoked by <code>JComponent</code>
* when the specified component is being painted.
*
* <p>By default this method fills the specified component with
* its background color if its {@code opaque} property is {@code true},
* and then immediately calls {@code paint}. In general this method need
* not be overridden by subclasses; all look-and-feel rendering code should
* reside in the {@code paint} method.
*
* @param g the <code>Graphics</code> context in which to paint
* @param c the component being painted;
* this argument is often ignored,
* but might be used if the UI object is stateless
* and shared by multiple components
*
* @see #paint
* @see javax.swing.JComponent#paintComponent
*/
public void update(Graphics g, JComponent c) {
if (c.isOpaque()) {
g.setColor(c.getBackground());
g.fillRect(0, 0, c.getWidth(),c.getHeight());
}
paint(g, c);
}