@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int r, int c) { Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, r, c); Long rev = (Long) table.getModel().getValueAt(table.convertRowIndexToModel(r), 0); if (commitRevision == rev) { if (modified) { comp.setForeground(Color.red); } else { comp.setForeground(Color.blue); } } else { comp.setForeground(Color.black); } if (c == 3) { setToolTipText(value.toString()); } else { setToolTipText(null); } return comp; }
public Component getTableCellRendererComponent( JTable aTable, Object aNumberValue, boolean aIsSelected, boolean aHasFocus, int aRow, int aColumn) { /* * Implementation Note : * It is important that no "new" be present in this * implementation (excluding exceptions): * if the table is large, then a large number of objects would be * created during rendering. */ if (aNumberValue == null) return this; Component renderer = super.getTableCellRendererComponent( aTable, aNumberValue, aIsSelected, aHasFocus, aRow, aColumn); Number value = (Number) aNumberValue; if (value.doubleValue() < 0) { renderer.setForeground(Color.red); } else { renderer.setForeground(fDarkGreen); } return this; }
/* * (non-Javadoc) * * @see org.protege.editor.owl.ui.renderer.OWLCellRenderer# * getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, * boolean, boolean, int, int) */ @Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component comp; objectToRender = value; if (objectToRender instanceof OWLAxiomChange) { value = ((OWLOntologyChange) objectToRender).getAxiom(); } else if (objectToRender instanceof OWLAxiomChange) { value = ((ImportChange) objectToRender).getImportDeclaration(); } else if (objectToRender instanceof AddOntologyAnnotation) { value = ((AddOntologyAnnotation) objectToRender).getAnnotation(); } else if (objectToRender instanceof RemoveOntologyAnnotation) { value = ((RemoveOntologyAnnotation) objectToRender).getAnnotation(); } else { // do nothing } if (value instanceof String) { comp = defaultTableCellRenderer.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); } else { comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } if (isSelected) { comp.setForeground(table.getSelectionForeground()); comp.setBackground(table.getSelectionBackground()); } else { comp.setForeground(table.getForeground()); comp.setBackground(table.getBackground()); } return comp; }
public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int vColIndex) { Component c = super.prepareRenderer(renderer, rowIndex, vColIndex); if (vColIndex < 1) { c.setForeground(Color.gray); } else { c.setForeground(getForeground()); } return c; }
@Override public Component getTableCellEditorComponent( JTable table, Object value, boolean isSelected, int row, int column) { Component comp = super.getTableCellEditorComponent(table, value, isSelected, row, column); if (!reader.getAttributeColumn(column - 1).isActivated()) { comp.setForeground(Color.LIGHT_GRAY); } else { comp.setForeground(Color.BLACK); } return comp; }
@Override public Component prepareRenderer(TableCellRenderer tcr, int row, int column) { Component c = super.prepareRenderer(tcr, row, column); if (isRowSelected(row)) { c.setForeground(getSelectionForeground()); c.setBackground(getSelectionBackground()); } else { c.setForeground(getForeground()); c.setBackground(row % 2 == 0 ? EVEN_COLOR : getBackground()); } return c; }
/** Shades alternate rows in different colors. */ @Override public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component c = super.prepareRenderer(renderer, row, column); if (!isCellSelected(row, column)) { c.setBackground(colorForRow(row)); c.setForeground(UIManager.getColor("Table.foreground")); } else { c.setBackground(UIManager.getColor("Table.selectionBackground")); c.setForeground(UIManager.getColor("Table.selectionForeground")); } return c; }
public void applyHighlighters(@NotNull Component rendererComponent, int row, boolean selected) { boolean fgUpdated = false; for (VcsLogHighlighter highlighter : myHighlighters) { Color color = highlighter.getForeground(myDataPack.getGraphFacade().getCommitAtRow(row), selected); if (color != null) { rendererComponent.setForeground(color); fgUpdated = true; } } if (!fgUpdated) { // reset highlighting if no-one wants to change it rendererComponent.setForeground(UIUtil.getTableForeground(selected)); } }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Color color = UIUtil.getTableFocusCellBackground(); Component component; T t = (T) value; try { UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, table.getSelectionBackground()); component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setText(t != null ? getItemText(t) : ""); if (component instanceof JLabel) { ((JLabel) component).setBorder(noFocusBorder); } } finally { UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, color); } final MyTableModel model = (MyTableModel) table.getModel(); component.setEnabled( ElementsChooser.this.isEnabled() && (myColorUnmarkedElements ? model.isElementMarked(row) : true)); final ElementProperties properties = myElementToPropertiesMap.get(t); if (component instanceof JLabel) { final Icon icon = properties != null ? properties.getIcon() : t != null ? getItemIcon(t) : null; JLabel label = (JLabel) component; label.setIcon(icon); label.setDisabledIcon(icon); } component.setForeground( properties != null && properties.getColor() != null ? properties.getColor() : (isSelected ? table.getSelectionForeground() : table.getForeground())); return component; }
public SimpleTextAttributes applyHighlighters( @NotNull Component rendererComponent, int row, int column, String text, boolean hasFocus, final boolean selected) { VcsLogHighlighter.VcsCommitStyle style = getStyle(row, column, text, hasFocus, selected); assert style.getBackground() != null && style.getForeground() != null && style.getTextStyle() != null; rendererComponent.setBackground(style.getBackground()); rendererComponent.setForeground(style.getForeground()); switch (style.getTextStyle()) { case BOLD: return SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES; case ITALIC: return SimpleTextAttributes.REGULAR_ITALIC_ATTRIBUTES; default: } return SimpleTextAttributes.REGULAR_ATTRIBUTES; }
@Override public Component getTableCellRendererComponent( javax.swing.JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component obj = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setHorizontalAlignment(SwingConstants.CENTER); if (isSelected) { obj.setBackground(new Color(200, 200, 218)); } else { obj.setBackground(null); } PositionStockInfoBean pos = model.getRowBean(row); if (column == 0) { String is = pos.getIs_ready_close(); if (is.equals("y")) { obj.setBackground(new Color(254, 142, 133)); } else { obj.setForeground(null); } } return obj; }
private static Pair<Image, Point> createDragImage( final Tree tree, final Component c, Point dragOrigin, boolean adjustToPathUnderDragOrigin) { if (c instanceof JComponent) { ((JComponent) c).setOpaque(true); } c.setForeground(tree.getForeground()); c.setBackground(tree.getBackground()); c.setFont(tree.getFont()); c.setSize(c.getPreferredSize()); final BufferedImage image = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) image.getGraphics(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); c.paint(g2); g2.dispose(); Point point = new Point(-image.getWidth(null) / 2, -image.getHeight(null) / 2); if (adjustToPathUnderDragOrigin) { TreePath path = tree.getPathForLocation(dragOrigin.x, dragOrigin.y); if (path != null) { Rectangle bounds = tree.getPathBounds(path); point = new Point(bounds.x - dragOrigin.x, bounds.y - dragOrigin.y); } } return new Pair<Image, Point>(image, point); }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Color color = UIUtil.getTableFocusCellBackground(); Component component; final Module module = value instanceof Module ? (Module) value : null; try { UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, table.getSelectionBackground()); component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (module != null) { setText( module.getName() + " (" + FileUtil.toSystemDependentName(module.getModuleFilePath()) + ")"); } if (component instanceof JLabel) { ((JLabel) component).setBorder(noFocusBorder); } } finally { UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, color); } component.setEnabled(ProcessedModulesTable.this.isEnabled()); if (component instanceof JLabel) { final Icon icon = module != null ? ModuleType.get(module).getIcon() : null; JLabel label = (JLabel) component; label.setIcon(icon); label.setDisabledIcon(icon); } component.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground()); return component; }
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component component = super.prepareRenderer(renderer, row, column); Color defaultBackgroundColor = Colors.WHITE.getColor(); MarginExpandablePanel marginExpandablePanel = (MarginExpandablePanel) component; if (marginExpandablePanel.getComponentCount() > 0) { Component nestedComponent = marginExpandablePanel.getComponent(0); nestedComponent.setForeground(ColorUtils.getContrastingColor(defaultBackgroundColor)); nestedComponent.setBackground(defaultBackgroundColor); } component.setForeground(ColorUtils.getContrastingColor(defaultBackgroundColor)); component.setBackground(defaultBackgroundColor); return component; }
/** * Returns the default table cell renderer. * * @param table the <code>JTable</code> * @param value the value to assign to the cell at <code>[row, column]</code> * @param isSelected true if cell is selected * @param hasFocus true if cell has focus * @param row the row of the cell to render * @param column the column of the cell to render * @return the default table cell renderer */ public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { ReadingList list = model.getLists()[row]; Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); comp.setForeground(list.isMissing() ? Color.GRAY : table.getForeground()); return comp; }
public static void makeEmphasized(Component widget) { // Set to bold amd add color Font font = widget.getFont(); if (!UserPreferences.readLocalePref() .equals("ko")) // HACK!!! refector with variable localeSupportsBold widget.setFont(new Font(font.getFamily(), Font.BOLD, font.getSize())); widget.setForeground(UIProperties.emphasisColor); }
/** * Sets the foreground and background color for a component and all components contained within * it. * * @param c the parent component of the component subtree to set * @param back the background color to set * @param fore the foreground color to set */ public static void setColor(Component c, Color back, Color fore) { c.setBackground(back); c.setForeground(fore); if (c instanceof Container) { Container con = (Container) c; for (int i = 0; i < con.getComponentCount(); ++i) setColor(con.getComponent(i), back, fore); } }
public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus) { ListCellRenderer renderer = comboBox.getRenderer(); Component c; Dimension d; c = renderer.getListCellRendererComponent( listBox, comboBox.getSelectedItem(), -1, false, false); c.setFont(comboBox.getFont()); if (comboBox.isEnabled()) { c.setForeground(comboBox.getForeground()); c.setBackground(comboBox.getBackground()); } else { c.setForeground(UIManager.getColor("ComboBox.disabledForeground")); c.setBackground(UIManager.getColor("ComboBox.disabledBackground")); } d = c.getPreferredSize(); currentValuePane.paintComponent(g, c, comboBox, bounds.x, bounds.y, bounds.width, d.height); }
private static Component setLabelColors( final Component label, final JTable table, final boolean isSelected, final int row) { if (label instanceof JComponent) { ((JComponent) label).setOpaque(true); } label.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground()); label.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground()); return label; }
// Implementation of TableCellRenderer interface public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { TableCellRenderer rend = super.getCellRenderer(row, column); Component c = rend.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); c.setBackground(getBack(isSelected, hasFocus, row, column)); c.setForeground(getFore(isSelected, hasFocus, row, column)); return c; }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value != null && highlight(table, value, isSelected, hasFocus, row, column)) { if (isSelected) { comp.setBackground(new Color((HIGHLIGHT_COLOR.getRGB() ^ comp.getBackground().getRGB()))); comp.setForeground(new Color(Color.BLACK.getRGB() ^ comp.getForeground().getRGB())); } else { comp.setBackground(HIGHLIGHT_COLOR); comp.setForeground(Color.BLACK); } } else { if (!isSelected) { comp.setBackground(Color.WHITE); comp.setForeground(Color.BLACK); } } return comp; }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); int rowN = table.convertRowIndexToModel(row); String s = table.getModel().getValueAt(rowN, 7).toString(); if (s.equalsIgnoreCase("yes")) { comp.setForeground(Color.LIGHT_GRAY); } else { comp.setForeground(null); } if (table.isCellEditable(row, column)) { comp.setBackground(Color.YELLOW); } return (comp); }
/** * Sets the foreground for an entire component hierarchy to the specified color. * * @param c the starting component * @param color the color to set */ public static void setComponentTreeForeground(Component c, Color color) { c.setForeground(color); Component[] children = getChildren(c); if (children != null) { for (int i = 0; i < children.length; i++) { setComponentTreeForeground(children[i], color); } } }
// cette fonction est appelée à chaque raffraichissement de l'interface public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); // si value est une instance de la classe Lemma alors on change la couleur des caracteres // de la ligne coorespondante a value if (value instanceof Lemma) { c.setForeground(new Color(0, 102, 0)); } // si value est une instance de la classe DocumentPart alors on change la couleur des caracteres // de la ligne coorespondante a value else if (value instanceof DocumentPart) { c.setForeground(new Color(102, 51, 0)); } else { // sinon on met la couleur de la ligne en noir c.setForeground(Color.BLACK); } return c; }
/** * Renderer method. * * @param table the table * @param value the value * @param isSelected is the cell selected * @param hasFocus has the cell the focus * @param row the cell row * @param column the cell column * @return the resulting component * @see * javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, * java.lang.Object, boolean, boolean, int, int) */ public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); ResultTableModel results = (ResultTableModel) table.getModel(); String status = (String) results.getValueAt(row, column); if (status.equals(ResultTableModel.SUCCESS)) { c.setForeground(Color.GREEN); setToolTipText(results.getMessage(row, column)); } if (status.equals(ResultTableModel.FAILURE)) { c.setForeground(Color.ORANGE); setToolTipText(results.getMessage(row, column)); } if (status.equals(ResultTableModel.ERROR)) { c.setForeground(Color.RED); setToolTipText(results.getMessage(row, column)); } return c; }
@Override protected void applyForeground(Component renderer, ComponentAdapter adapter) { if (!adapter.isSelected()) { Object colorMemory = ((JComponent) renderer).getClientProperty("rendererColorMemory.foreground"); if (colorMemory instanceof ColorMemory) { renderer.setForeground(((ColorMemory) colorMemory).color); } else { ((JComponent) renderer) .putClientProperty( "rendererColorMemory.foreground", new ColorMemory(renderer.getForeground())); } } }
@Override public Component getListCellRendererComponent( JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { final MagicDeck deck = (MagicDeck) value; final Component c = super.getListCellRendererComponent(list, deck.getName(), index, isSelected, cellHasFocus); if (deck.isValid() == false) { if (invalidDeckFont == null) { final Map<TextAttribute, Object> attributes = new HashMap<>(); attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); invalidDeckFont = c.getFont().deriveFont(attributes); } c.setFont(invalidDeckFont); c.setForeground(isSelected ? list.getSelectionForeground() : Color.RED.darker()); } return c; }
/** * Adds a message consisting of one or more lines of text, which will be displayed using the * specified font and color. */ public void addMessage(String text, Font font, Color color) { theLabel = null; if (text.indexOf('\n') >= 0) theLabel = new MultiLineLabel(text); else theLabel = new Label(text); // theLabel.addKeyListener(this); c.gridx = 0; c.gridy = y; c.gridwidth = 2; c.anchor = GridBagConstraints.WEST; c.insets = getInsets(text.equals("") ? 0 : 10, 20, 0, 0); c.fill = GridBagConstraints.HORIZONTAL; grid.setConstraints(theLabel, c); if (font != null) theLabel.setFont(font); if (color != null) theLabel.setForeground(color); add(theLabel); c.fill = GridBagConstraints.NONE; y++; }
@Override public Component getTreeCellRendererComponent( JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); c.setFont(MacFontUtils.ITUNES_FONT); c.setForeground(tree.getForeground()); c.setBackground(tree.getBackground()); setBackground(tree.getBackground()); return c; }
/** * Sets the colour scheme based upon a {@link ColourScheme}. The colour scheme changes only after * all queued messages are displayed. Note that this is not thread safe and should execute on the * Swing event dispatching thread. This should not be invoked directly - use {@link * #setColourScheme(ColourScheme)} or {@link #setDefaultColourScheme()} instead. * * @param colourScheme The colour scheme to set */ private void setColourScheme(final ColourScheme colourScheme) { final Color c1 = colourScheme.getC1(); final Color c2 = colourScheme.getC2(); final Color c3 = colourScheme.getC3(); final Color c4 = colourScheme.getC4(); final Color readableText = colourScheme.getReadableText(); if (nimbus != null) { UIManager.put("nimbusBase", c1); UIManager.put("nimbusBlueGrey", c2); UIManager.put("control", c3); UIManager.put("textBackground", c1); UIManager.put("textForeground", readableText); UIManager.put("infoText", readableText); UIManager.put("menuText", readableText); UIManager.put("TextArea.background", c4); try { UIManager.setLookAndFeel(nimbus); } catch (Exception ex) { } } else { JOptionPane.showMessageDialog( this, NIMBUS_UNSUPPORTED, "Nimbus Error", JOptionPane.ERROR_MESSAGE); for (Component c : backgroundColourableComponents) { c.setBackground(c3); } } for (Component c : complementaryAmenableForegroundColourableComponents) { c.setForeground(readableText); } // update the current colour scheme updateColourScheme(); survivor.setColourScheme(colourScheme); // maintain consistency with the colour scheme that is shown to be selected setCurrentColourSchemeSelected(); }