Example usage for javax.swing JComponent getBackground

List of usage examples for javax.swing JComponent getBackground

Introduction

In this page you can find the example usage for javax.swing JComponent getBackground.

Prototype

@Transient
public Color getBackground() 

Source Link

Document

Gets the background color of this component.

Usage

From source file:org.jdal.swing.validation.BackgroundErrorProcessor.java

/**
 * {@inheritDoc}/*from  w w  w .  j  av  a  2 s.  com*/
 */
public void processError(Object control, FieldError error) {
    if (control instanceof JComponent) {
        JComponent c = (JComponent) control;
        colorMap.put(c, c.getBackground());
        ((JComponent) c).setBackground(errorColor);
        if (messageSource != null)
            c.setToolTipText(messageSource.getMessage(error, null));
    }
}

From source file:org.underworldlabs.swing.plaf.base.AcceleratorToolTipUI.java

public void paint(Graphics g, JComponent c) {

    UIUtils.antialias(g);//from  w  ww  .  ja  v  a  2  s .co m

    Font font = c.getFont();
    FontMetrics metrics = c.getFontMetrics(font);

    Dimension size = c.getSize();
    if (c.isOpaque()) {
        g.setColor(c.getBackground());
        g.fillRect(0, 0, size.width + 20, size.height);
    }

    JToolTip toolTip = (JToolTip) c;
    String tipText = getTipText(toolTip);

    if (!MiscUtils.isNull(tipText)) {

        Insets insets = c.getInsets();
        Rectangle paintTextR = new Rectangle(insets.left, insets.top, size.width - (insets.left + insets.right),
                size.height - (insets.top + insets.bottom));

        Color foreground = c.getForeground();
        g.setColor(foreground);
        g.setFont(font);

        g.drawString(tipText, paintTextR.x + 3, paintTextR.y + metrics.getAscent());

        String acceleratorString = getAcceleratorStringForRender(toolTip);
        if (StringUtils.isNotBlank(acceleratorString)) {

            Font acceleratorFont = font.deriveFont(font.getSize() - 1f);
            g.setFont(acceleratorFont);
            g.setColor(GUIUtils.getSlightlyBrighter(foreground, 2.0f));

            g.drawString(acceleratorString, paintTextR.x + 6 + metrics.stringWidth(tipText),
                    paintTextR.y + metrics.getAscent());
        }

    }

}