@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean isFocused, int row, int col) { if (isSelected) { setBackground(table.getSelectionBackground()); setForeground(table.getSelectionForeground()); } else { setForeground(table.getForeground()); if (row % 2 == 0) { setBackground(EVEN_COLOR); } else { setBackground(ODD_COLOR); } } if (value != null && value instanceof String) { String pubType = (String) value; if (pubType.equals(IInfoModel.PUBLISHED_TYPE_GLOBAL)) { setIcon(WEB_ICON); } else { setIcon(HOME_ICON); } this.setText(""); } else { setIcon(null); this.setText(value == null ? "" : value.toString()); } return this; }
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; }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean isFocused, int row, int col) { if (isSelected) { setBackground(table.getSelectionBackground()); setForeground(table.getSelectionForeground()); } else { setForeground(table.getForeground()); if (row % 2 == 0) { setBackground(EVEN_COLOR); } else { setBackground(ODD_COLOR); } } if (value != null && value instanceof Boolean) { Boolean imported = (Boolean) value; if (imported.booleanValue()) { this.setIcon(FLAG_ICON); } else { this.setIcon(null); } this.setText(""); } else { setIcon(null); this.setText(value == null ? "" : value.toString()); } return this; }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean isFocused, int row, int col) { NLaboImportSummary summary = (NLaboImportSummary) tableModel.getObject(row); if (isSelected) { this.setBackground(table.getSelectionBackground()); this.setForeground(table.getSelectionForeground()); } else { if (summary != null && summary.getKarteId() == null) { this.setBackground(UNCONSTRAINED_COLOR); } else { if ((row & (1)) == 0) { this.setBackground(EVEN_COLOR); } else { this.setBackground(ODD_COLOR); } } this.setForeground(table.getForeground()); } if (value != null && value instanceof String) { this.setText((String) value); } else { this.setText(value == null ? "" : value.toString()); } return this; }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { textLabel.setFont(table.getFont()); textLabel.setText(Objects.toString(value, "")); textLabel.setBorder(hasFocus ? focusCellHighlightBorder : noFocusBorder); FontMetrics fm = table.getFontMetrics(table.getFont()); Insets i = textLabel.getInsets(); int swidth = iconLabel.getPreferredSize().width + fm.stringWidth(textLabel.getText()) + i.left + i.right; int cwidth = table.getColumnModel().getColumn(column).getWidth(); dim.width = swidth > cwidth ? cwidth : swidth; if (isSelected) { textLabel.setOpaque(true); textLabel.setForeground(table.getSelectionForeground()); textLabel.setBackground(table.getSelectionBackground()); iconLabel.setIcon(sicon); } else { textLabel.setOpaque(false); textLabel.setForeground(table.getForeground()); textLabel.setBackground(table.getBackground()); iconLabel.setIcon(nicon); } return panel; }
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; }
/** * 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; }
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; }
@Override protected void fillPage( Page page, JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Color foreground = isSelected ? table.getSelectionForeground() : table.getForeground(); Color background = isSelected ? table.getSelectionBackground() : table.getBackground(); renderCellValue(page, value, foreground, background, isSelected); }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (isSelected) { setForeground(table.getSelectionForeground()); setBackground(table.getSelectionBackground()); } else { setForeground(table.getForeground()); setBackground(table.getBackground()); } setFont(table.getFont()); setText(Objects.toString(value, "")); return this; }
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 { setForeground(table.getForeground()); setBackground(table.getBackground()); } // Select the current value setSelectedItem(value); return this; }
public Component getTableCellEditorComponent( JTable table, Object value, boolean isSelected, int row, int column) { if (isSelected) { button.setForeground(table.getSelectionForeground()); button.setBackground(table.getSelectionBackground()); } else { button.setForeground(table.getForeground()); button.setBackground(table.getBackground()); laLigneSelectionnee = row; } label = (value == null) ? "" : value.toString(); button.setText(label); isPushed = true; return button; }
@NotNull @Override public Component getTableCellRendererComponent( @NotNull JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final RegistryValue v = ((MyTableModel) table.getModel()).getRegistryValue(row); myLabel.setIcon(null); myLabel.setText(null); myLabel.setHorizontalAlignment(SwingConstants.LEFT); Color fg = isSelected ? table.getSelectionForeground() : table.getForeground(); Color bg = isSelected ? table.getSelectionBackground() : table.getBackground(); if (v != null) { switch (column) { case 0: myLabel.setIcon(v.isRestartRequired() ? RESTART_ICON : null); myLabel.setHorizontalAlignment(SwingConstants.CENTER); break; case 1: myLabel.setText(v.getKey()); break; case 2: if (v.asColor(null) != null) { myLabel.setIcon(createColoredIcon(v.asColor(null))); } else if (v.isBoolean()) { final JCheckBox box = new JCheckBox(); box.setSelected(v.asBoolean()); box.setBackground(bg); return box; } else { myLabel.setText(v.asString()); } } myLabel.setOpaque(true); myLabel.setFont( myLabel.getFont().deriveFont(v.isChangedFromDefault() ? Font.BOLD : Font.PLAIN)); myLabel.setForeground(fg); myLabel.setBackground(bg); } return myLabel; }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); String str = Objects.toString(value, ""); if (highlighter.isHighlightableCell(row, column)) { setText("<html><u>" + str); setForeground(isSelected ? table.getSelectionForeground() : HIGHLIGHT); setBackground(isSelected ? table.getSelectionBackground().darker() : table.getBackground()); } else { setText(str); setForeground(isSelected ? table.getSelectionForeground() : table.getForeground()); setBackground(isSelected ? table.getSelectionBackground() : table.getBackground()); } return this; }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { getModel().setRollover(highlighter.isHighlightableCell(row, column)); if (isSelected) { setForeground(table.getSelectionForeground()); super.setBackground(table.getSelectionBackground()); } else { setForeground(table.getForeground()); setBackground(table.getBackground()); // setBackground(row % 2 == 0 ? table.getBackground() : Color.WHITE); //Nimbus } setSelected(Objects.equals(value, Boolean.TRUE)); return this; }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final JComponent rendererComponent = (JComponent) myBaseRenderer.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); if (isSelected) { rendererComponent.setBackground(table.getSelectionBackground()); rendererComponent.setForeground(table.getSelectionForeground()); } else { final Color bg = table.getBackground(); rendererComponent.setBackground(bg); rendererComponent.setForeground(table.getForeground()); } rendererComponent.setOpaque(isSelected); return rendererComponent; }
private JCheckBox tune( final Object value, final boolean isSelected, final int row, final JTable table, boolean hasFocus) { final Color bg = table.getBackground(); final Color fg = table.getForeground(); final Color selBg = table.getSelectionBackground(); final Color selFg = table.getSelectionForeground(); setForeground(isSelected ? selFg : fg); setBackground(isSelected ? selBg : bg); if (value == null) { setState(State.DONT_CARE); } else { setSelected((Boolean) value); } return this; }
/** * Returns the default table cell renderer. * * @param table the JTable * @param value the value to assign to the cell at [row, column] * @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) { /* the following is the similar to DefaultTableCellRenderer */ if (isSelected) { super.setForeground(UIHelper.BG_COLOR); super.setBackground(new Color(0, 104, 56, 175)); } else { super.setForeground(table.getForeground()); if (columnColors.get(column) == null) { super.setBackground(UIHelper.BG_COLOR); } else { super.setBackground(columnColors.get(column)); } } setFont(UIHelper.VER_11_PLAIN); if (hasFocus) { setBorder(new DragBorder()); if (table.isCellEditable(row, column)) { super.setForeground(UIHelper.BG_COLOR); super.setBackground(UIHelper.DARK_GREEN_COLOR); } } else { setBorder(noFocusBorder); } /* this method has been changed for formula feature */ setValue(value); // DefaulTableCellRenderer code // begin optimization to avoid painting background Color back = getBackground(); boolean colorMatch = (back != null) && (back.equals(table.getBackground())) && table.isOpaque(); setOpaque(!colorMatch); // end optimization to aviod painting background return this; }
public Component getTableCellEditorComponent( JTable table, Object value, boolean isSelected, int row, int column) { if (isSelected) { button.setForeground(table.getSelectionForeground()); button.setBackground(table.getSelectionBackground()); } else { button.setForeground(table.getForeground()); button.setBackground(table.getBackground()); } String[] jakasnazwa = value.toString().split(" "); label = (value == null) ? "" : jakasnazwa[0]; button.setText(label); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { main.sendMessage( new JSONObject().put("cmd", "connectToGame").put("identifier", jakasnazwa[1])); main.getMainPanel().requestFocus(); } }); return button; }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Color foreground = null; Color background = null; Font font = null; TableModel model = table.getModel(); if (model instanceof AttributiveCellTableModel) { CellAttribute cellAtt = ((AttributiveCellTableModel) model).getCellAttribute(); if (cellAtt instanceof ColoredCell) { foreground = ((ColoredCell) cellAtt).getForeground(row, column); background = ((ColoredCell) cellAtt).getBackground(row, column); } if (cellAtt instanceof CellFont) { font = ((CellFont) cellAtt).getFont(row, column); } } if (isSelected) { setForeground((foreground != null) ? foreground : table.getSelectionForeground()); setBackground(table.getSelectionBackground()); } else { setForeground((foreground != null) ? foreground : table.getForeground()); setBackground((background != null) ? background : table.getBackground()); } setFont((font != null) ? font : table.getFont()); if (hasFocus) { setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); if (table.isCellEditable(row, column)) { setForeground( (foreground != null) ? foreground : UIManager.getColor("Table.focusCellForeground")); setBackground(UIManager.getColor("Table.focusCellBackground")); } } else { setBorder(noFocusBorder); } setValue(value); return this; }
public Component getTableCellRendererComponent( JTable table, Setting owner, Object value, boolean isSelected, boolean hasFocus, boolean isEnabled, int row, int column) { // renderer.setMargin(new Insets(0, 2, 4, 2)); if (isSelected) { renderer.setForeground(table.getSelectionForeground()); panel.setBackground(table.getSelectionBackground()); blank1.setBackground(table.getSelectionBackground()); blank2.setBackground(table.getSelectionBackground()); } else { renderer.setForeground(table.getForeground()); panel.setBackground(table.getBackground()); blank1.setBackground(table.getBackground()); blank2.setBackground(table.getBackground()); } if (hasFocus) { panel.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); } else { panel.setBorder(new EmptyBorder(1, 2, 2, 1)); } if (value instanceof Color) { Color col = (Color) value; // System.out.println("setting background to "+col.toString()); renderer.setText("[" + col.getRed() + "," + col.getGreen() + "," + col.getBlue() + "]"); renderer.setEnabled(isEnabled); renderer.setFont(font); colourPanel.setBackground(col); } else if (value instanceof ArrayList) { ArrayList values = (ArrayList) value; if (values.size() > 0) { // if we have multiple properties selected. Color last = null; boolean allSame = true; for (int i = 0; i < values.size(); i++) { if (values.get(i) instanceof Color) { Color str = (Color) values.get(i); if (last != null) { if (!str.equals(last)) { allSame = false; break; } last = str; } else { last = str; } } } if (allSame) { renderer.setText( "[" + last.getRed() + "," + last.getGreen() + "," + last.getBlue() + "]"); renderer.setEnabled(isEnabled); renderer.setFont(font); colourPanel.setBackground(last); } else { renderer.setText("(Different values)"); renderer.setEnabled(isEnabled); renderer.setFont(font); colourPanel.setBackground(Color.lightGray); panel.setBackground(Color.lightGray); blank1.setBackground(Color.lightGray); blank2.setBackground(Color.lightGray); } } } return panel; }
protected void preinit(JTable table, boolean isSelected, boolean hasFocus) { setBackground(isSelected ? table.getSelectionBackground() : table.getBackground()); setForeground(isSelected ? table.getSelectionForeground() : table.getForeground()); setBorder(hasFocus ? UIUtil.getTableFocusCellHighlightBorder() : NO_FOCUS_BORDER); }