Java Code Examples for javax.swing.JTable#getBackground()
The following examples show how to use
javax.swing.JTable#getBackground() .
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: 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 2
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 3
Source File: SwingRenderer.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void updateComponentSelectedState(JComponent c, boolean isSelected, JTable table, int row, int column, boolean hasFocus) { Color fg = null; Color bg = null; JTable.DropLocation dropLocation = table.getDropLocation(); if (dropLocation != null && !dropLocation.isInsertRow() && !dropLocation.isInsertColumn() && dropLocation.getRow() == row && dropLocation.getColumn() == column) { isSelected = true; } if (isSelected) { c.setForeground(fg == null ? table.getSelectionForeground() : fg); c.setBackground(bg == null ? table.getSelectionBackground() : bg); } else { Color background = unselectedBackground != null ? unselectedBackground : table.getBackground(); c.setForeground(unselectedForeground != null ? unselectedForeground : table.getForeground()); c.setBackground(background); } c.setFont(table.getFont()); }
Example 4
Source File: render.java From knife with MIT License | 5 votes |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if(isSelected){ setForeground(table.getForeground()); super.setBackground(table.getBackground()); }else{ setForeground(table.getForeground()); setBackground(table.getBackground()); } boolean isMale = ((Boolean)value).booleanValue(); setSelectedIndex(isMale? 0 : 1); return this; }
Example 5
Source File: ObdItemTableRenderer.java From AndrOBD with GNU General Public License v3.0 | 5 votes |
/** * set visualisation parameters referring to given table * * @param table * - the table object to refer to ... */ private void setParentTable(JTable table) { parentTable = table; // set the font only once, and then just use it parentFont = table.getFont(); setFont(parentFont); // get background color from Table bgColor = table.getBackground(); // get selection color from Table selColor = table.getSelectionBackground(); }
Example 6
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 7
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 8
Source File: DateTimeTableEditor.java From LGoodDatePicker with MIT License | 4 votes |
/** * getTableCellRendererComponent, Returns the renderer that is used for drawing the cell. This * is required by the TableCellRenderer interface. * * For additional details, see the Javadocs for the function: * TableCellRenderer.getTableCellRendererComponent(). */ @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { // Save the supplied value to the DateTimePicker. setCellEditorValue(value); // Draw the appropriate background colors to indicate a selected or unselected state. if (isSelected) { if (matchTableSelectionBackgroundColor) { Color selectionBackground = table.getSelectionBackground(); dateTimePicker.setBackground(selectionBackground); dateTimePicker.datePicker.setBackground(selectionBackground); dateTimePicker.timePicker.setBackground(selectionBackground); dateTimePicker.datePicker.getComponentDateTextField().setBackground(selectionBackground); dateTimePicker.timePicker.getComponentTimeTextField().setBackground(selectionBackground); } else { dateTimePicker.datePicker.zDrawTextFieldIndicators(); dateTimePicker.timePicker.zDrawTextFieldIndicators(); } } if (!isSelected) { if (matchTableBackgroundColor) { Color tableBackground = table.getBackground(); dateTimePicker.setBackground(tableBackground); dateTimePicker.datePicker.setBackground(tableBackground); dateTimePicker.timePicker.setBackground(tableBackground); dateTimePicker.datePicker.getComponentDateTextField().setBackground(tableBackground); dateTimePicker.timePicker.getComponentTimeTextField().setBackground(tableBackground); } else { dateTimePicker.datePicker.zDrawTextFieldIndicators(); dateTimePicker.timePicker.zDrawTextFieldIndicators(); } } // Draw the appropriate borders to indicate a focused or unfocused state. if (hasFocus) { dateTimePicker.setBorder(borderFocusedCell); } else { dateTimePicker.setBorder(borderUnfocusedCell); } // If needed, adjust the minimum row height for the table. zAdjustTableRowHeightIfNeeded(table); // This fixes a bug where the picker text could "move around" during a table resize event. dateTimePicker.datePicker.getComponentDateTextField().setScrollOffset(0); dateTimePicker.timePicker.getComponentTimeTextField().setScrollOffset(0); // Return the DateTimePicker component. return dateTimePicker; }
Example 9
Source File: ComponentCellRenderer.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
/** * @see javax.swing.table.TableCellRenderer#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) { JPanel newPanel = new JPanel(); newPanel.setLayout(new OverlayLayout(newPanel)); Color bgColor; if (isSelected) bgColor = table.getSelectionBackground(); else bgColor = table.getBackground(); newPanel.setBackground(bgColor); if (hasFocus) { Border border = null; if (isSelected) border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); if (border == null) border = UIManager.getBorder("Table.focusCellHighlightBorder"); if (border != null) newPanel.setBorder(border); } if (value != null) { if (value instanceof JComponent) { newPanel.add((JComponent) value); } else { JLabel newLabel = new JLabel(); if (value instanceof IIsotope) { IIsotope is = (IIsotope) value; newLabel.setText(is.getSymbol()); } else { newLabel.setText(value.toString()); } if (font != null) newLabel.setFont(font); else if (table.getFont() != null) newLabel.setFont(table.getFont()); newPanel.add(newLabel); } if (createTooltips) newPanel.setToolTipText(value.toString()); } return newPanel; }
Example 10
Source File: PeakStatusCellRenderer.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
/** * @see javax.swing.table.TableCellRenderer#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) { JPanel newPanel = new JPanel(); newPanel.setLayout(new OverlayLayout(newPanel)); Color bgColor; if (isSelected) bgColor = table.getSelectionBackground(); else bgColor = table.getBackground(); newPanel.setBackground(bgColor); if (hasFocus) { Border border = null; if (isSelected) border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); if (border == null) border = UIManager.getBorder("Table.focusCellHighlightBorder"); /* * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug, * otherwise setBorder() may throw a NullPointerException */ if ((border != null) && (border.getBorderInsets(newPanel) != null)) { newPanel.setBorder(border); } } if (value != null) { FeatureStatus status = (FeatureStatus) value; switch (status) { case DETECTED: newPanel.add(greenCircle); break; case ESTIMATED: newPanel.add(yellowCircle); break; case MANUAL: newPanel.add(orangeCircle); break; default: newPanel.add(redCircle); break; } newPanel.setToolTipText(status.toString()); } else { newPanel.add(redCircle); } return newPanel; }
Example 11
Source File: FormattedCellRenderer.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
/** * @see javax.swing.table.TableCellRenderer#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) { JPanel newPanel = new JPanel(); Color bgColor; if (isSelected) bgColor = table.getSelectionBackground(); else bgColor = table.getBackground(); newPanel.setBackground(bgColor); if (hasFocus) { Border border = null; if (isSelected) border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); if (border == null) border = UIManager.getBorder("Table.focusCellHighlightBorder"); /* * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug, * otherwise setBorder() may throw a NullPointerException */ if ((border != null) && (border.getBorderInsets(newPanel) != null)) { newPanel.setBorder(border); } } if (value != null) { String text; if (value instanceof Number) text = format.format((Number) value); else text = value.toString(); JLabel newLabel = new JLabel(text, JLabel.CENTER); if (font != null) newLabel.setFont(font); else if (table.getFont() != null) newLabel.setFont(table.getFont()); newPanel.add(newLabel); } return newPanel; }
Example 12
Source File: CompoundIdentityCellRenderer.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
/** * @see javax.swing.table.TableCellRenderer#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) { JLabel newLabel = new JLabel(); newLabel.setHorizontalAlignment(JLabel.LEFT); newLabel.setFont(defaultFont); newLabel.setOpaque(true); Color bgColor; if (isSelected) bgColor = table.getSelectionBackground(); else bgColor = table.getBackground(); newLabel.setBackground(bgColor); if (hasFocus) { Border border = null; if (isSelected) border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); if (border == null) border = UIManager.getBorder("Table.focusCellHighlightBorder"); /* * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug, * otherwise setBorder() may throw a NullPointerException */ if ((border != null) && (border.getBorderInsets(newLabel) != null)) { newLabel.setBorder(border); } } if (value instanceof PeakIdentity) { PeakIdentity identity = (PeakIdentity) value; newLabel.setText(identity.getName()); String toolTipText = identity.getDescription(); newLabel.setToolTipText(toolTipText); } return newLabel; }
Example 13
Source File: PeakShapeCellRenderer.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
/** * @see javax.swing.table.TableCellRenderer#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) { JPanel newPanel = new JPanel(); newPanel.setLayout(new OverlayLayout(newPanel)); Color bgColor; if (isSelected) bgColor = table.getSelectionBackground(); else bgColor = table.getBackground(); newPanel.setBackground(bgColor); if (value instanceof Feature) { Feature peak = (Feature) value; double maxHeight = 0; PeakShapeNormalization norm = parameters.getParameter(PeakListTableParameters.peakShapeNormalization).getValue(); if (norm == null) norm = PeakShapeNormalization.ROWMAX; switch (norm) { case GLOBALMAX: maxHeight = peakList.getDataPointMaxIntensity(); break; case ROWMAX: int rowNumber = peakList.getPeakRowNum(peak); maxHeight = peakList.getRow(rowNumber).getDataPointMaxIntensity(); break; default: maxHeight = peak.getRawDataPointsIntensityRange().upperEndpoint(); break; } PeakXICComponent xic = new PeakXICComponent(peak, maxHeight); // newPanel.add(xic); // newPanel.setToolTipText(xic.getToolTipText()); } if (value instanceof PeakListRow) { PeakListRow plRow = (PeakListRow) value; RawDataFile[] dataFiles = peakList.getRawDataFiles().toArray(RawDataFile[]::new); Feature[] peaks = new Feature[dataFiles.length]; for (int i = 0; i < dataFiles.length; i++) { peaks[i] = plRow.getPeak(dataFiles[i]); } // CombinedXICComponent xic = new CombinedXICComponent(peaks, plRow.getID()); // newPanel.add(xic); // newPanel.setToolTipText(xic.getToolTipText()); } return newPanel; }
Example 14
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; }
Example 15
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 16
Source File: QueryTableCellRenderer.java From netbeans with Apache License 2.0 | 4 votes |
public static TableCellStyle getCellStyle(JTable table, IssueTable issueTable, IssueNode<?>.IssueProperty<?> p, boolean isSelected, int row) { TableCellStyle style = getDefaultCellStyle(table, issueTable, p, isSelected, row); try { // set text format and background depending on selection and issue status IssueStatusProvider.Status status = p.getStatus(); if(status != IssueStatusProvider.Status.SEEN) { switch(status) { case INCOMING_NEW : style.format = isSelected ? style.format : issueNewFormat; style.background = isSelected ? newHighlightColor : style.background; style.foreground = isSelected ? table.getBackground() : style.foreground; break; case INCOMING_MODIFIED : style.format = isSelected ? style.format : issueModifiedFormat; style.background = isSelected ? modifiedHighlightColor : style.background; style.foreground = isSelected ? table.getBackground() : style.foreground; break; } } Object o = p.getValue(); if(o instanceof String) { String s = (String) o; if(s == null) { s = ""; } // NOI18N s = TextUtils.escapeForHTMLLabel(s); StringBuilder sb = new StringBuilder(); sb.append("<html>"); // NOI18N sb.append(s); if(status == null) { status = p.getStatus(); } switch(status) { case INCOMING_NEW : sb.append("<br>").append(issueNewFormat.format(new Object[] { labelNew }, new StringBuffer(), null)); // NOI18N sb.append(msgNew); break; case INCOMING_MODIFIED : sb.append("<br>").append(issueModifiedFormat.format(new Object[] { labelModified }, new StringBuffer(), null)); // NOI18N sb.append(MessageFormat.format(msgModified, p.getRecentChanges())); break; } sb.append("</html>"); // NOI18N style.tooltip = sb.toString(); } } catch (Exception ex) { IssueTable.LOG.log(Level.WARNING, null, ex); } return style; }
Example 17
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 18
Source File: PeakStatusCellRenderer.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
/** * @see javax.swing.table.TableCellRenderer#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) { JPanel newPanel = new JPanel(); newPanel.setLayout(new OverlayLayout(newPanel)); Color bgColor; if (isSelected) bgColor = table.getSelectionBackground(); else bgColor = table.getBackground(); newPanel.setBackground(bgColor); if (hasFocus) { Border border = null; if (isSelected) border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); if (border == null) border = UIManager.getBorder("Table.focusCellHighlightBorder"); /* * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug, * otherwise setBorder() may throw a NullPointerException */ if ((border != null) && (border.getBorderInsets(newPanel) != null)) { newPanel.setBorder(border); } } if (value != null) { FeatureStatus status = (FeatureStatus) value; switch (status) { case DETECTED: newPanel.add(greenCircle); break; case ESTIMATED: newPanel.add(yellowCircle); break; case MANUAL: newPanel.add(orangeCircle); break; default: newPanel.add(redCircle); break; } newPanel.setToolTipText(status.toString()); } else { newPanel.add(redCircle); } return newPanel; }
Example 19
Source File: FormattedCellRenderer.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
/** * @see javax.swing.table.TableCellRenderer#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) { JPanel newPanel = new JPanel(); Color bgColor; if (isSelected) bgColor = table.getSelectionBackground(); else bgColor = table.getBackground(); newPanel.setBackground(bgColor); if (hasFocus) { Border border = null; if (isSelected) border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); if (border == null) border = UIManager.getBorder("Table.focusCellHighlightBorder"); /* * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug, * otherwise setBorder() may throw a NullPointerException */ if ((border != null) && (border.getBorderInsets(newPanel) != null)) { newPanel.setBorder(border); } } if (value != null) { String text; if (value instanceof Number) text = format.format((Number) value); else text = value.toString(); JLabel newLabel = new JLabel(text, JLabel.CENTER); if (font != null) newLabel.setFont(font); else if (table.getFont() != null) newLabel.setFont(table.getFont()); newPanel.add(newLabel); } return newPanel; }
Example 20
Source File: CompoundIdentityCellRenderer.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
/** * @see javax.swing.table.TableCellRenderer#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) { JLabel newLabel = new JLabel(); newLabel.setHorizontalAlignment(JLabel.LEFT); newLabel.setFont(defaultFont); newLabel.setOpaque(true); Color bgColor; if (isSelected) bgColor = table.getSelectionBackground(); else bgColor = table.getBackground(); newLabel.setBackground(bgColor); if (hasFocus) { Border border = null; if (isSelected) border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); if (border == null) border = UIManager.getBorder("Table.focusCellHighlightBorder"); /* * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug, * otherwise setBorder() may throw a NullPointerException */ if ((border != null) && (border.getBorderInsets(newLabel) != null)) { newLabel.setBorder(border); } } if (value instanceof PeakIdentity) { PeakIdentity identity = (PeakIdentity) value; newLabel.setText(identity.getName()); String toolTipText = identity.getDescription(); newLabel.setToolTipText(toolTipText); } return newLabel; }