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

The following are Jave code examples for showing how to use isOpaque() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: freecol   File: FreeColButtonUI.java   View Source Code Vote up 6 votes
@Override
public void paint(Graphics g, JComponent c) {
    LAFUtilities.setProperties(g, c);

    if (c.isOpaque()) {
        ImageLibrary.drawTiledImage("image.background.FreeColButton", g, c, null);
    }
    super.paint(g, c);

    AbstractButton a = (AbstractButton) c;
    if (a.isRolloverEnabled()) {
        Point p = MouseInfo.getPointerInfo().getLocation();
        SwingUtilities.convertPointFromScreen(p, c);
        boolean rollover = c.contains(p);
        if (rollover) {
            paintButtonPressed(g, (AbstractButton) c);
        }
    }
}
 
Example 2
Project: incubator-netbeans   File: DnDSupport.java   View Source Code Vote up 5 votes
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 3
Project: rapidminer   File: MenuBarUI.java   View Source Code Vote up 5 votes
@Override
public void update(Graphics g, JComponent c) {
	if (c.isOpaque()) {
		Color oldColor = g.getColor();
		CachedPainter.drawMenuBarBackground(c, g, 0, 0, c.getWidth(), c.getHeight());
		g.setColor(oldColor);
	}
}
 
Example 4
Project: freecol   File: FreeColDialog.java   View Source Code Vote up 5 votes
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 5
Project: freecol   File: FreeColOptionPaneUI.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 */
@Override
public void paint(Graphics g, JComponent c) {
    if (c.isOpaque()) {
        ImageLibrary.drawTiledImage("image.background.FreeColOptionPane",
                                    g, c, null);
    }
}
 
Example 6
Project: freecol   File: FreeColToolTipUI.java   View Source Code Vote up 5 votes
@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 7
Project: FreeCol   File: FreeColTextAreaUI.java   View Source Code Vote up 5 votes
@Override
public void paintBackground(java.awt.Graphics g) {
    JComponent c = getComponent();
    if (c.isOpaque()) {
        ImageLibrary.drawTiledImage("image.background.FreeColTextArea", g, c, null);
    }
}
 
Example 8
Project: freecol   File: FreeColTextAreaUI.java   View Source Code Vote up 5 votes
@Override
public void paintBackground(java.awt.Graphics g) {
    JComponent c = getComponent();
    if (c.isOpaque()) {
        ImageLibrary.drawTiledImage("image.background.FreeColTextArea", g, c, null);
    }
}
 
Example 9
Project: OpenJSharp   File: AquaPanelUI.java   View Source Code Vote up 5 votes
@Override
public final void update(final Graphics g, final JComponent c) {
    if (c.isOpaque()) {
        AquaUtils.fillRect(g, c);
    }
    paint(g, c);
}
 
Example 10
Project: jdk8u-jdk   File: AquaPanelUI.java   View Source Code Vote up 5 votes
@Override
public final void update(final Graphics g, final JComponent c) {
    if (c.isOpaque()) {
        AquaUtils.fillRect(g, c);
    }
    paint(g, c);
}
 
Example 11
Project: openjdk-jdk10   File: AquaPanelUI.java   View Source Code Vote up 5 votes
@Override
public final void update(final Graphics g, final JComponent c) {
    if (c.isOpaque()) {
        AquaUtils.fillRect(g, c);
    }
    paint(g, c);
}
 
Example 12
Project: FreeCol   File: FreeColDialog.java   View Source Code Vote up 5 votes
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 13
Project: FreeCol   File: FreeColOptionPaneUI.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 */
@Override
public void paint(Graphics g, JComponent c) {
    if (c.isOpaque()) {
        ImageLibrary.drawTiledImage("image.background.FreeColOptionPane",
                                    g, c, null);
    }
}
 
Example 14
Project: FreeCol   File: FreeColToolTipUI.java   View Source Code Vote up 5 votes
@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 15
Project: FreeCol   File: FreeColTextFieldUI.java   View Source Code Vote up 5 votes
@Override
public void paintBackground(java.awt.Graphics g) {
    JComponent c = getComponent();

    if (c.isOpaque()) {
        ImageLibrary.drawTiledImage("image.background.FreeColTextField", g, c, null);
    }
}
 
Example 16
Project: rapidminer   File: ProgressBarUI.java   View Source Code Vote up 4 votes
@Override
protected void paintDeterminate(Graphics g, JComponent c) {
	boolean compressed = Boolean.parseBoolean(String.valueOf(progressBar
			.getClientProperty(RapidLookTools.PROPERTY_PROGRESSBAR_COMPRESSED)));

	int y = 0;
	int x = 0;
	int w;
	int h;
	if (compressed) {
		x = (int) (c.getWidth() * 0.67);
		w = (int) (c.getWidth() * 0.33);
		y = 3;
		h = c.getHeight() - 6;
	} else {
		w = c.getWidth();
		h = c.getHeight() / 2;
	}

	int amountFull = getAmountFull(progressBar.getInsets(), w, h);

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	if (c.isOpaque()) {
		if (c.getParent() != null) {
			g2.setColor(c.getParent().getBackground());
		} else {
			g2.setColor(c.getBackground());
		}
		g2.fillRect(x, y, c.getWidth(), c.getHeight());
	}

	g2.setColor(Colors.PROGRESSBAR_BACKGROUND);
	g2.fillRoundRect(x + 1, y + 1, w - 2, h - 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	g2.setColor(Colors.PROGRESSBAR_BORDER);
	g2.drawRoundRect(x + 1, y + 1, w - 2, h - 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	Paint gp = new GradientPaint(x, y + 3, Colors.PROGRESSBAR_DETERMINATE_FOREGROUND_GRADIENT_START, x, h - 5,
			Colors.PROGRESSBAR_DETERMINATE_FOREGROUND_GRADIENT_END);
	g2.setPaint(gp);
	g2.fillRoundRect(x + 3, y + 3, amountFull - 5, h - 5, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);

	drawString(g2, w, h, compressed);
}
 
Example 17
Project: rapidminer   File: ProgressBarUI.java   View Source Code Vote up 4 votes
@Override
protected void paintIndeterminate(Graphics g, JComponent c) {
	boolean compressed = Boolean.parseBoolean(String.valueOf(progressBar
			.getClientProperty(RapidLookTools.PROPERTY_PROGRESSBAR_COMPRESSED)));

	int y = 0;
	int x = 0;
	int w;
	int h;
	if (compressed) {
		x = (int) (c.getWidth() * 0.67);
		w = (int) (c.getWidth() * 0.33);
		y = 3;
		h = c.getHeight() - 6;
	} else {
		w = c.getWidth();
		h = c.getHeight() / 2;
	}

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	if (c.isOpaque()) {
		if (c.getParent() != null) {
			g2.setColor(c.getParent().getBackground());
		} else {
			g2.setColor(c.getBackground());
		}
		g2.fillRect(x, y, c.getWidth(), c.getHeight());
	}

	g2.setColor(Colors.PROGRESSBAR_BACKGROUND);
	g2.fillRoundRect(x + 1, y + 1, w - 2, h - 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	g2.setColor(Colors.PROGRESSBAR_BORDER);
	g2.drawRoundRect(x + 1, y + 1, w - 2, h - 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	// make sure we don't draw over the boundaries
	RoundRectangle2D clipRect = new RoundRectangle2D.Double(x + 3, y + 3, w - 5, h - 5,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);
	g2.setClip(clipRect);

	for (double xCoord = x + -4 * ANIMATION_BAR_LENGTH + System.currentTimeMillis() * ANIMATION_SPEED
			% (2 * ANIMATION_BAR_LENGTH); xCoord < x + w + 2 * ANIMATION_BAR_LENGTH;) {
		g2.setColor(Colors.PROGRESSBAR_INDETERMINATE_FOREGROUND_1);
		g2.fill(createIntermediateShape(xCoord, ANIMATION_BAR_LENGTH, h));
		xCoord += ANIMATION_BAR_LENGTH;
		g2.setColor(Colors.PROGRESSBAR_INDETERMINATE_FOREGROUND_2);
		g2.fill(createIntermediateShape(xCoord, ANIMATION_BAR_LENGTH, h));
		xCoord += ANIMATION_BAR_LENGTH;
	}
	g2.setClip(null);

	drawString(g2, w, h, compressed);
}
 
Example 18
Project: OpenJSharp   File: ComponentUI.java   View Source Code Vote up 3 votes
/**
 * 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
Project: jdk8u-jdk   File: ComponentUI.java   View Source Code Vote up 3 votes
/**
 * 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
Project: openjdk-jdk10   File: ComponentUI.java   View Source Code Vote up 3 votes
/**
 * 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);
}