Java Code Examples for javax.swing.JTable#getSelectionForeground()
The following examples show how to use
javax.swing.JTable#getSelectionForeground() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SectorRowsEditor.java From ramus with GNU General Public License v3.0 | 5 votes |
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) { if (isSelected) { super.setForeground(table.getSelectionForeground()); super.setBackground(table.getSelectionBackground()); } else { super.setForeground(table.getForeground()); super.setBackground(table.getBackground()); } setFont(table.getFont()); if (hasFocus) { Border border = null; if (isSelected) { border = UIManager .getBorder("Table.focusSelectedCellHighlightBorder"); } if (border == null) { border = UIManager .getBorder("Table.focusCellHighlightBorder"); } setBorder(border); } else { setBorder(noFocusBorder); } return this; }
Example 2
Source File: MBooleanTableCellRenderer.java From javamelody with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) { if (isSelected) { super.setForeground(table.getSelectionForeground()); super.setBackground(table.getSelectionBackground()); } else { super.setForeground(table.getForeground()); if (MTable.BICOLOR_LINE != null && row % 2 == 0) { super.setBackground(MTable.BICOLOR_LINE); } else { super.setBackground(table.getBackground()); } } if (hasFocus) { setBorder(BORDER); } else { setBorder(null); } setEnabled(table.isCellEditable(row, column)); if (value instanceof Boolean) { final boolean selected = ((Boolean) value).booleanValue(); this.setSelected(selected); // this.setToolTipText(selected ? "vrai" : "false"); return this; } final JLabel label = (JLabel) table.getDefaultRenderer(String.class) .getTableCellRendererComponent(table, null, isSelected, hasFocus, row, column); if (value == null) { label.setText(null); } else { label.setText("??"); } return label; }
Example 3
Source File: YesNoRenderer.java From RipplePower with Apache License 2.0 | 5 votes |
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 { 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(noFocusBorder); } setValue(value); Color back = getBackground(); boolean colorMatch = (back != null) && (back.equals(table.getBackground())) && table.isOpaque(); setOpaque(!colorMatch); return this; }
Example 4
Source File: OddEvenRowColorModel.java From RipplePower with Apache License 2.0 | 5 votes |
public Color getForeground(int row, boolean selected, JTable table) { if (selected) { return table.getSelectionForeground(); } else { return fore; } }
Example 5
Source File: MosaicExpressionsPanel.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final boolean enabled = table.isEnabled(); setText((String) value); if (isSelected) { super.setForeground(table.getSelectionForeground()); super.setBackground(table.getSelectionBackground()); } else if (!enabled) { super.setForeground(UIManager.getColor("TextField.inactiveForeground")); super.setBackground(table.getBackground()); } else { super.setForeground(table.getForeground()); super.setBackground(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(noFocusBorder); } setValue(value); return this; }
Example 6
Source File: TabDataRenderer.java From netbeans with Apache License 2.0 | 4 votes |
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column ) { renderer.clear(); Rectangle rect = table.getCellRect( row, column, true ); renderer.setSize( rect.width, rect.height ); if( value instanceof TabData ) { TabData tab = ( TabData ) value; String text = tab.getText(); Icon icon = tab.getIcon(); Color colBackground = isSelected ? table.getSelectionBackground() : table.getBackground(); Color colForeground = isSelected ? table.getSelectionForeground() : table.getForeground(); boolean isActive = (activeBackground != null || underlineColor != null) ? TabbedImpl.isActive(table) : false; if (!isSelected && isActive && activeBackground != null) { colBackground = activeBackground; } for( TabDecorator td : decorators ) { Color c = td.getBackground( tab, isSelected ); if( null != c ) colBackground = c; c = td.getForeground( tab, isSelected ); if( null != c ) colForeground = c; String s = td.getText( tab ); if( null != s ) text = s; Icon i = td.getIcon( tab ); if( null != i ) { icon = i; } } boolean isHover = (hoverBackground != null && TabTableUI.isHover(table, row, column)); if (isHover) { colBackground = hoverBackground; } renderer.label.setText( text ); renderer.label.setIcon( icon ); renderer.label.setFont( table.getFont() ); renderer.setBackground( colBackground ); renderer.label.setForeground( colForeground ); renderer.tabData = tab; renderer.isSelected = isSelected; renderer.isActive = isActive; renderer.tabsLocation = (table instanceof TabTable) ? ((TabTable)table).getTabsLocation() : JTabbedPane.TOP; if( table instanceof TabTable ) { TabTable tabTable = ( TabTable ) table; if( isClosable(tab) ) { boolean inCloseButton = tabTable.isCloseButtonHighlighted( row, column ); renderer.closeButton.setVisible( true ); renderer.closeButton.getModel().setRollover( inCloseButton ); renderer.closeButton.getModel().setArmed( inCloseButton ); } else { renderer.closeButton.setVisible( false ); } } } return renderer; }
Example 7
Source File: CoverageReportTopComponent.java From netbeans with Apache License 2.0 | 4 votes |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value == null) { return new DefaultTableCellRenderer().getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } if (isSelected) { super.setForeground(table.getSelectionForeground()); super.setBackground(table.getSelectionBackground()); } else { super.setForeground(table.getForeground()); super.setBackground(table.getBackground()); } setFont(table.getFont()); if (hasFocus) { Border border = null; if (isSelected) { border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); // NOI18N } if (border == null) { border = UIManager.getBorder("Table.focusCellHighlightBorder"); // NOI18N } setBorder(border); } else { setBorder(new EmptyBorder(1, 1, 1, 1)); } FileCoverageSummary summary = (FileCoverageSummary) table.getValueAt(row, -1); FileObject file = summary.getFile(); setText(summary.getDisplayName()); if (file != null && file.isValid()) { try { DataObject dobj = DataObject.find(file); Node node = dobj.getNodeDelegate(); Image icon = node.getIcon(BeanInfo.ICON_COLOR_32x32); setIcon(new ImageIcon(icon)); } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); } } else { setIcon(null); } return this; }
Example 8
Source File: EncryptBackActionCellRenderer.java From pgptool with GNU General Public License v3.0 | 4 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (table == null) { return this; } lbl.setFont(table.getFont().deriveFont(Font.BOLD)); Color fg = null; Color bg = null; JTable.DropLocation dropLocation = table.getDropLocation(); if (dropLocation != null && !dropLocation.isInsertRow() && !dropLocation.isInsertColumn() && dropLocation.getRow() == row && dropLocation.getColumn() == column) { fg = UIManager.getColor("Table.dropCellForeground"); bg = UIManager.getColor("Table.dropCellBackground"); isSelected = true; } if (isSelected) { super.setForeground(fg == null ? table.getSelectionForeground() : fg); super.setBackground(bg == null ? table.getSelectionBackground() : bg); } else { Color background = unselectedBackground != null ? unselectedBackground : table.getBackground(); if (background == null || background instanceof javax.swing.plaf.UIResource) { Color alternateColor = UIManager.getColor("Table.alternateRowColor"); if (alternateColor != null && row % 2 != 0) { background = alternateColor; } } super.setForeground(unselectedForeground != null ? unselectedForeground : table.getForeground()); super.setBackground(background); } setFont(table.getFont()); if (hasFocus) { Border border = null; if (isSelected) { border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); } if (border == null) { border = UIManager.getBorder("Table.focusCellHighlightBorder"); } setBorder(border); if (!isSelected && table.isCellEditable(row, column)) { Color col; col = UIManager.getColor("Table.focusCellForeground"); if (col != null) { super.setForeground(col); } col = UIManager.getColor("Table.focusCellBackground"); if (col != null) { super.setBackground(col); } } } else { setBorder(getNoFocusBorder()); } return this; }