Example usage for javax.swing JTable getForeground

List of usage examples for javax.swing JTable getForeground

Introduction

In this page you can find the example usage for javax.swing JTable getForeground.

Prototype

@Transient
public Color getForeground() 

Source Link

Document

Gets the foreground color of this component.

Usage

From source file:com.sander.verhagen.frame.LineWrapCellRenderer.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    String text = value.toString();
    setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
    setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
    int columnWidth = table.getColumnModel().getColumn(column).getWidth();
    setSize(columnWidth, 0 /* don't know yet */);
    setText(text);//  www  . j a  v a  2 s. c  o  m

    int fontHeight = this.getFontMetrics(this.getFont()).getHeight();
    if (StringUtils.isEmpty(text)) {
        table.setRowHeight(row, fontHeight);
    } else {
        table.setRowHeight(row, fontHeight * getLineCount(this));
    }
    return this;
}

From source file:Main.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    if (isSelected) {
        setForeground(table.getSelectionForeground());
        super.setBackground(table.getSelectionBackground());
    } else {/*from ww w.j a  va  2  s. c  o  m*/
        setForeground(table.getForeground());
        setBackground(table.getBackground());
    }
    setSelectedItem(value);
    return this;
}

From source file:GenderRenderer.java

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

    if (isSelected) {
        setForeground(table.getSelectionForeground());
        super.setBackground(table.getSelectionBackground());
    } else {/*www. j av  a 2s .  c om*/
        setForeground(table.getForeground());
        setBackground(table.getBackground());
    }

    boolean isMale = ((Boolean) value).booleanValue();
    setSelectedIndex(isMale ? 0 : 1);
    return this;
}

From source file:com.mirth.connect.client.ui.ImageCellRenderer.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    if (isSelected) {
        setForeground(table.getSelectionForeground());
        super.setBackground(table.getSelectionBackground());
    } else {/*from w  w  w . j a v  a  2s .  c o  m*/
        setForeground(table.getForeground());
        setBackground(table.getBackground());
    }

    // MIRTH-2186 Java sometimes calls this method with a hard-coded null value so tablecellrenderers must explicitly check for null.
    // Only observed so far on Mac OSX.
    // http://stackoverflow.com/questions/3054775/java-swing-jtable-strange-behavior-from-getaccessiblechild-method-resulting
    if (value != null) {
        CellData data = (CellData) value;

        setText(data.getText());

        setIcon(data.getIcon());
        setHorizontalAlignment(LEFT);

        if (data.getIcon() == null && StringUtils.isEmpty(data.getText())) {
            setHorizontalAlignment(CENTER);
            setText("--");
        }
    }

    return this;
}

From source file:com.github.alexfalappa.nbspringboot.navigator.RequestMethodCellRenderer.java

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    if (!isSelected) {
        if (value == null) {
            setForeground(table.getForeground());
            setBackground(table.getBackground());
        } else if (value instanceof RequestMethod) {
            final RequestMethod reqMethod = (RequestMethod) value;
            setForeground(fgColors.get(reqMethod));
            setBackground(bgColors.get(reqMethod));
        }/*ww w.  j  av  a2s.  c  o m*/
    }
    return this;
}

From source file:com.emr.schemas.ButtonColumn.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    if (isSelected) {
        renderButton.setForeground(table.getSelectionForeground());
        renderButton.setBackground(table.getSelectionBackground());
    } else {// w  w  w .  j  a  v a 2s .  c om
        renderButton.setForeground(table.getForeground());
        renderButton.setBackground(UIManager.getColor("Button.background"));
    }

    if (hasFocus) {
        renderButton.setBorder(focusBorder);
    } else {
        renderButton.setBorder(originalBorder);
    }

    //      renderButton.setText( (value == null) ? "" : value.toString() );
    renderButton.setText(btnText);

    return renderButton;
}

From source file:ExtendedTableCellRenderer.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    if (isSelected) {
        super.setForeground(table.getSelectionForeground());
        super.setBackground(table.getSelectionBackground());

    } else {/*from  w  w  w .  j  a v  a  2  s . com*/
        super.setForeground((unselectedForeground != null) ? unselectedForeground : table.getForeground());
        super.setBackground((unselectedBackground != null) ? unselectedBackground : table.getBackground());
    }

    setFont(table.getFont());

    if (hasFocus) {
        setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
        if (table.isCellEditable(row, column)) {
            super.setForeground(UIManager.getColor("Table.focusCellForeground"));
            super.setBackground(UIManager.getColor("Table.focusCellBackground"));
        }
    } else {
        setBorder(NO_FOCUS_BORDER);
    }

    setValue(value);

    Color background = getBackground();
    boolean colorMatch = (background != null) && (background.equals(table.getBackground())) && table.isOpaque();
    setOpaque(!colorMatch);

    return this;
}

From source file:ExpenseReport.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    if (value instanceof Boolean) {
        Boolean b = (Boolean) value;
        setSelected(b.booleanValue());//from ww  w . ja  v  a2 s .c  om
    }

    setBackground(isSelected && !hasFocus ? table.getSelectionBackground() : table.getBackground());
    setForeground(isSelected && !hasFocus ? table.getSelectionForeground() : table.getForeground());

    setFont(table.getFont());
    setBorder(hasFocus ? UIManager.getBorder("Table.focusCellHighlightBorder") : m_noFocusBorder);

    return this;
}

From source file:com.diversityarrays.kdxplore.trials.PlotCellRenderer.java

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    boolean cellSelected = table.isCellSelected(row, column);

    super.getTableCellRendererComponent(table, value, cellSelected, hasFocus, row, column);

    setToolTipText(null);/*www  . jav a 2 s. c  o m*/

    commentMarker = null;
    sampleIconType = SampleIconType.NORMAL;
    if (value instanceof Plot) {
        Plot plot = (Plot) value;
        handlePlot(table, isSelected, hasFocus, row, column, cellSelected, plot);
        if (!plot.isActivated()) {
            sampleIconType = isSelected ? SampleIconType.INACTIVE_PLOT_SELECTED : SampleIconType.INACTIVE_PLOT;
        }
    } else {
        if (cellSelected) {
            this.setBackground(table.getSelectionBackground());
            this.setForeground(table.getSelectionForeground());
        } else {
            this.setBackground(table.getBackground());
            this.setForeground(table.getForeground());
        }
    }

    return this;
}

From source file:com.diversityarrays.kdxplore.trials.PlotCellRenderer.java

private void handlePlot(JTable table, boolean isSelected, boolean hasFocus, int row, int column,
        boolean cellSelected, Plot plot) {
    StringBuilder sb = new StringBuilder("<HTML>");

    if (plotVisitList != null) {
        PlotVisitGroup pvg = plotVisitList.getPlotVisitGroup(plot);
        if (pvg != null) {
            WalkSegment ws = pvg.walkSegment;
            sb.append(ws.segmentIndex + 1).append(":").append(ws.orientationUDLR.unicodeArrow).append("<BR>");
        }/*from w w w .  j a  v a 2s. c  o  m*/
    }

    if (showUserPlotId) {
        sb.append("<b>").append(plot.getUserPlotId()).append("</b>");
    }

    //      Collection<String> tagLabels = plot.getTagLabels();
    // Instead of the above, collect for all SampleGroups
    Set<String> tagLabels = plot.getTagsBySampleGroup().entrySet().stream().flatMap(e -> e.getValue().stream())
            .map(tag -> tag.getLabel()).collect(Collectors.toSet());

    addAnnotations(plot, tagLabels, sb);

    String plotType = plot.getPlotType();
    if (plotType != null && !plotType.isEmpty()) {
        sb.append(": <i>").append(StringUtil.htmlEscape(plotType)).append("</i>");
    }

    Pair<Integer, Integer> cell = new Pair<Integer, Integer>(row, column);

    Map<TraitInstance, Comparable<?>> tempMap = new HashMap<TraitInstance, Comparable<?>>();
    if (temporaryValues.containsKey(cell)) {
        tempMap = temporaryValues.get(cell);
    }

    boolean anyAttributesAdded = false;

    if (attributeNames != null && !attributeNames.isEmpty()) {
        if (plot.plotAttributeValues != null) {
            for (PlotAttributeValue pav : plot.plotAttributeValues) {
                if (attributeNames.contains(pav.plotAttributeName)) {
                    anyAttributesAdded = true;
                    String attrValue = pav.getAttributeValue();
                    sb.append("<br/>");
                    PlotAttribute pa = plotAttributeProvider.transform(pav);
                    sb.append("<i>").append(StringUtil.htmlEscape(pa.getPlotAttributeName())).append("</i>");
                    sb.append(": ");
                    if (attrValue == null) {
                        sb.append("-no-value-");
                    } else {
                        sb.append(StringUtil.htmlEscape(attrValue));
                    }
                }
            }
        }
    }

    String tttResult = null;
    if (!traitInstancesByTraitId.isEmpty()) {
        // Appends html to sb. Also sets commentMarker
        tttResult = collectCellHtml(isSelected, plot, sb, tempMap);
    }
    if (!Check.isEmpty(tagLabels)) {
        StringBuilder tmp = new StringBuilder();
        if (tttResult != null) {
            if (!tttResult.startsWith("<HTML>")) {
                tmp.append("<HTML>");
            }
            tmp.append(tttResult).append("<br>");
        } else {
            tmp.append("<HTML>");
        }
        String tagsep = "";
        for (String tag : tagLabels) {
            tmp.append(tagsep).append(tag);
            tagsep = ", ";
        }
        tttResult = tmp.toString();
    }
    setToolTipText(tttResult);

    if (activeInstance != null) {
        Color c = colorProvider == null ? table.getSelectionBackground()
                : colorProvider.getTraitInstanceColor(activeInstance).getBackground();

        if (!cellSelected) {
            cellSelected = fieldViewSelectionModel.isSelectedPlot(plot);
        }

        if (cellSelected) {
            this.setBackground(c);
            this.setForeground(table.getForeground());
        } else {
            this.setBackground(table.getBackground());
            this.setForeground(table.getForeground());
        }
    } else {
        if (cellSelected) {
            this.setBackground(table.getSelectionBackground());
            this.setForeground(table.getSelectionForeground());
        } else {
            this.setBackground(table.getBackground());
            this.setForeground(table.getForeground());
        }
    }

    setText(sb.toString());
    if (isSelected && hasFocus) {
        setBorder(focusSelectedCellHighlightBorder);
    } else {
        setBorder(border);
    }
}