Java Code Examples for javax.swing.JComponent#isOpaque()

The following examples show how to use javax.swing.JComponent#isOpaque() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: seaglass   File: SeaGlassViewportUI.java    License: Apache License 2.0 6 votes vote down vote up
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());
            }
        }
    }
}
 
Example 2
@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();
        }
    }
 }
 
Example 3
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);
    }
}
 
Example 4
@Override
public final void update(final Graphics g, final JComponent c) {
    if (c.isOpaque()) {
        AquaUtils.fillRect(g, c);
    }
    paint(g, c);
}
 
Example 5
Source Project: FlatLaf   File: FlatProgressBarUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void update( Graphics g, JComponent c ) {
	if( c.isOpaque() )
		FlatUIUtils.paintParentBackground( g, c );

	paint( g, c );
}
 
Example 6
Source Project: FlatLaf   File: FlatViewportUI.java    License: Apache License 2.0 5 votes vote down vote up
@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 );
}
 
Example 7
@Override
public final void update(final Graphics g, final JComponent c) {
    if (c.isOpaque()) {
        AquaUtils.fillRect(g, c);
    }
    paint(g, c);
}
 
Example 8
@Override
public final void update(final Graphics g, final JComponent c) {
    if (c.isOpaque()) {
        AquaUtils.fillRect(g, c);
    }
    paint(g, c);
}
 
Example 9
@Override
public final void update(final Graphics g, final JComponent c) {
    if (c.isOpaque()) {
        AquaUtils.fillRect(g, c);
    }
    paint(g, c);
}
 
Example 10
Source Project: seaglass   File: DesktopPanePainter.java    License: Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 11
/**
 * 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);
}
 
Example 12
@Override
public void paintBackground(java.awt.Graphics g) {
    JComponent c = getComponent();
    if (c.isOpaque()) {
        ImageLibrary.drawTiledImage("image.background.FreeColTextArea",
                                    g, c, null);
    }
}
 
Example 13
Source Project: netbeans   File: DnDSupport.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 14
Source Project: FlatLaf   File: FlatSpinnerUI.java    License: Apache License 2.0 4 votes vote down vote up
@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 );
}
 
Example 15
/**
 * 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);
}
 
Example 16
/**
 * 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);
}
 
Example 17
Source Project: hottub   File: ComponentUI.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 18
/**
 * 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);
}
 
Example 19
/**
 * 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);
}
 
Example 20
Source Project: Bytecoder   File: ComponentUI.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}