Example usage for javax.swing JComponent setForeground

List of usage examples for javax.swing JComponent setForeground

Introduction

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

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The foreground color of the component.")
public void setForeground(Color fg) 

Source Link

Document

Sets the foreground color of this component.

Usage

From source file:Main.java

public static void setDelimitedColor(JComponent component, boolean selected) {
    component.setForeground(selected ? DELIMITER_BG : NORMAL_FG);
    component.setBackground(selected ? NORMAL_BG : DELIMITER_BG);
}

From source file:Main.java

/**
 * Sets foreground color of component and all of its children.
 *
 * @param component  component to modify
 * @param foreground new foreground color
 * @param childsOnly whether exclude component from changes or not
 *///from  w  w  w  .j a v a2 s  .  c  om
public static void setForegroundRecursively(final JComponent component, final Color foreground,
        final boolean childsOnly) {
    if (!childsOnly) {
        component.setForeground(foreground);
    }
    for (int i = 0; i < component.getComponentCount(); i++) {
        if (component.getComponent(i) instanceof JComponent) {
            setForegroundRecursively((JComponent) component.getComponent(i), foreground, false);
        }
    }
}

From source file:MyButtonUI.java

public void mouseEntered(MouseEvent e) {
    JComponent c = (JComponent) e.getComponent();
    c.setForeground(m_foregroundActive);
    c.repaint();
}

From source file:MyButtonUI.java

public void mouseExited(MouseEvent e) {
    JComponent c = (JComponent) e.getComponent();
    c.setForeground(m_foregroundNormal);
    c.repaint();
}

From source file:DragColorTextFieldDemo.java

/**
 * Overridden to import a Color if it is available.
 * getChangesForegroundColor is used to determine whether the foreground or
 * the background color is changed.//from  ww w . j ava 2s .co m
 */
public boolean importData(JComponent c, Transferable t) {
    if (hasColorFlavor(t.getTransferDataFlavors())) {
        try {
            Color col = (Color) t.getTransferData(colorFlavor);
            if (getChangesForegroundColor()) {
                c.setForeground(col);
            } else {
                c.setBackground(col);
            }
            return true;
        } catch (UnsupportedFlavorException ufe) {
            System.out.println("importData: unsupported data flavor");
        } catch (IOException ioe) {
            System.out.println("importData: I/O exception");
        }
    }
    return false;
}

From source file:com.projity.pm.graphic.network.NetworkRenderer.java

public void paintNode(Graphics2D g, GraphicNode node) {
    Rectangle bounds = getBounds(node);
    if (isEditing(node)) {
        editor.paintEditor(node);/*from  ww  w .ja  va 2  s . c om*/
    } else {
        JComponent c = renderer.getRendererComponent(node, ((NetworkParams) graphInfo).getZoom());
        if (container == null) {
            //c=new JLabel("test");
            c.setDoubleBuffered(false);
            c.setOpaque(false);
            c.setForeground(Color.BLACK);
            c.setSize(bounds.width, bounds.height);
            g.translate(bounds.x, bounds.y);
            c.doLayout();
            c.print(g);
            g.translate(-bounds.x, -bounds.y);
        } else
            rendererPane.paintComponent(g, c, container, bounds.x, bounds.y, bounds.width, bounds.height, true);
    }
}

From source file:de.unentscheidbar.validation.swing.trigger.ChangeTriggerTest.java

@Override
protected void doNotProvokeTrigger(Iterable<JComponent> components) {

    for (final JComponent c : components) {
        robot.focusAndWaitForFocusGain(c);
        robot.focusAndWaitForFocusGain(gui.get(dummyKey));
        runInEdt(new Runnable() {

            @Override//www.  j a  va2 s  . c  o m
            public void run() {

                Color col;
                while ((col = new Color(rnd.nextInt())).equals(c.getForeground()))
                    ;
                c.setForeground(col);
                c.setBackground(col);
            }
        });
    }
}

From source file:eu.ggnet.dwoss.receipt.unit.UnitView.java

private void updateValidationStatus(JComponent component, Survey vs, StringBuilder sb) {
    EventQueue.invokeLater(() -> {
        component.setToolTipText(vs.getMessage());
        component.setForeground(vs.getStatus().getColor());
    });//ww  w. j  a v a  2  s .  com
    sb.append("- ").append(component.getName()).append(": ").append(vs.getStatus()).append(" : ")
            .append(vs.getMessage()).append("\n");
}

From source file:com.sec.ose.osi.ui.frm.main.identification.stringmatch.table.JTableInfoForSMFile.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    JComponent comp = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
            column);/*from ww w.  j  av a 2  s.  c o m*/
    if (value != null) {
        if (table.getColumnName(column).equals("Version") || table.getColumnName(column).equals("Pending Hits")
                || table.getColumnName(column).equals("Status")
                || table.getColumnName(column).equals("Identified Hits")
                || table.getColumnName(column).equals("Files")) {
            setHorizontalAlignment(SwingConstants.CENTER);
        } else {
            setHorizontalAlignment(SwingConstants.LEFT);
        }

        comp.setToolTipText(String.valueOf(value));
        if (table.getValueAt(row, TableModelForSMFile.COL_STATUS) != null
                && table.getValueAt(row, TableModelForSMFile.COL_STATUS).toString().equals("Identified")) {

            comp.setFont(new Font("Arial", Font.BOLD | Font.ITALIC, 12));
            comp.setForeground(new Color(20, 20, 20));
        } else if (table.getValueAt(row, TableModelForSMFile.COL_STATUS).toString().equals("Declared")) {
            comp.setForeground(new Color(150, 150, 150));
        } else {
            comp.setForeground(new Color(20, 20, 20));
        }
    } else {
        comp.setToolTipText(null);
    }
    return comp;
}

From source file:com.sec.ose.osi.ui.frm.main.identification.codematch.table.JTableInfoForCMFile.java

synchronized public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
        boolean hasFocus, int row, int column) {

    JComponent comp = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
            column);//from  w  ww . j  ava  2s. c  om
    if (value == null) {
        comp.setToolTipText(null);
        return comp;
    }

    comp.setToolTipText(String.valueOf(value));

    if (row >= table.getRowCount()) {
        log.debug("row > table.getRowCount()");
        return comp;
    }

    switch (column) {
    case TableModelForCMFile.COL_COMPONENT_NAME:
    case TableModelForCMFile.COL_LICENSE_NAME:
        setHorizontalAlignment(SwingConstants.LEFT);
        break;

    case TableModelForCMFile.COL_VERSION_NAME:
    case TableModelForCMFile.COL_USAGE:
    case TableModelForCMFile.COL_STATUS:
    case TableModelForCMFile.COL_PERCENTAGE:
    case TableModelForCMFile.COL_MATCHED_FILE:
        setHorizontalAlignment(SwingConstants.CENTER);
        break;
    }

    if (table.getValueAt(row, TableModelForCMFile.COL_STATUS) == null)
        return comp;
    String status = table.getValueAt(row, TableModelForCMFile.COL_STATUS).toString();
    String licenseName = table.getValueAt(row, TableModelForCMFile.COL_LICENSE_NAME).toString();

    if (status.equals(AbstractMatchInfo.IDENTIFIED)) {

        comp.setFont(new Font("Arial", Font.BOLD | Font.ITALIC, 12));
        comp.setForeground(NORMAL_COLOR);

    } else if ((status.equals(AbstractMatchInfo.REJECTED)) || (status.equals(AbstractMatchInfo.DECLARED))) {

        comp.setForeground(new Color(150, 150, 150));

    } else if (status.equals(AbstractMatchInfo.PENDING)) {

        if (identifiedStringSearchLicense != null && !identifiedStringSearchLicense.equals("")) {
            String currentRowLicense = "" + licenseName;
            if (identifiedStringSearchLicense.equals(currentRowLicense)) {
                comp.setForeground(NORMAL_COLOR);
            } else {
                comp.setForeground(GRAY_COLOR);
            }
        } else {
            comp.setForeground(NORMAL_COLOR);
        }
    }

    return comp;
}