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

The following examples show how to use javax.swing.JComponent#isOpaque() . 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: SeaGlassViewportUI.java    From seaglass with 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
Source File: AquaPanelUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void update(final Graphics g, final JComponent c) {
    if (c.isOpaque()) {
        AquaUtils.fillRect(g, c);
    }
    paint(g, c);
}
 
Example 3
Source File: DnDSupport.java    From netbeans with 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 4
Source File: FreeColTextAreaUI.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void paintBackground(java.awt.Graphics g) {
    JComponent c = getComponent();
    if (c.isOpaque()) {
        ImageLibrary.drawTiledImage("image.background.FreeColTextArea",
                                    g, c, null);
    }
}
 
Example 5
Source File: WindowsTaskPaneGroupUI.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 6
Source File: DesktopPanePainter.java    From seaglass with 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 7
Source File: AquaPanelUI.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void update(final Graphics g, final JComponent c) {
    if (c.isOpaque()) {
        AquaUtils.fillRect(g, c);
    }
    paint(g, c);
}
 
Example 8
Source File: FreeColToolTipUI.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
@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 9
Source File: AquaPanelUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void update(final Graphics g, final JComponent c) {
    if (c.isOpaque()) {
        AquaUtils.fillRect(g, c);
    }
    paint(g, c);
}
 
Example 10
Source File: FlatViewportUI.java    From FlatLaf with 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 11
Source File: FlatProgressBarUI.java    From FlatLaf with 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 12
Source File: AquaPanelUI.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void update(final Graphics g, final JComponent c) {
    if (c.isOpaque()) {
        AquaUtils.fillRect(g, c);
    }
    paint(g, c);
}
 
Example 13
Source File: FreeColDialog.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
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 14
Source File: FlatSpinnerUI.java    From FlatLaf with 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
Source File: ComponentUI.java    From openjdk-jdk9 with 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 16
Source File: ComponentUI.java    From hottub with 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 17
Source File: ComponentUI.java    From jdk8u-jdk with 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
Source File: ComponentUI.java    From jdk8u60 with 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 19
Source File: ComponentUI.java    From jdk8u-jdk with 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 20
Source File: ComponentUI.java    From Bytecoder with 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);
}