Java Code Examples for javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent()
The following examples show how to use
javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent() .
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: TableUIBridge.java From darklaf with MIT License | 6 votes |
/** * Returns the baseline. * * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} * @see javax.swing.JComponent#getBaseline(int, int) * @since 1.6 */ public int getBaseline(final JComponent c, final int width, final int height) { super.getBaseline(c, width, height); UIDefaults lafDefaults = UIManager.getLookAndFeelDefaults(); Component renderer = (Component) lafDefaults.get(BASELINE_COMPONENT_KEY); if (renderer == null) { DefaultTableCellRenderer tcr = new DefaultTableCellRenderer(); renderer = tcr.getTableCellRendererComponent(table, "a", false, false, -1, -1); lafDefaults.put(BASELINE_COMPONENT_KEY, renderer); } renderer.setFont(table.getFont()); int rowMargin = table.getRowMargin(); return renderer.getBaseline(Integer.MAX_VALUE, table.getRowHeight() - rowMargin) + rowMargin / 2; }
Example 2
Source File: DistanceTableCellRenderer.java From dsworkbench with Apache License 2.0 | 6 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); Component c = renderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); JLabel l = (JLabel) c; double v = (Double) value; if (unit.equals(UnknownUnit.getSingleton())) { l.setText(nf.format(value)); } else { double speedInMinutes = v * unit.getSpeed(); l.setText(DSCalculator.formatTimeInMinutes(speedInMinutes)); } Color col = null; if (v <= markerMin) { col = ColorGradientHelper.getGradientColor(100f, Color.RED, Color.GREEN); } else if ((v > markerMin) && (v < markerMax)) { double range = markerMax - markerMin; double val = v - markerMin; col = ColorGradientHelper.getGradientColor((float) (100.0 - (100.0 * val / range)), Color.RED, Color.GREEN); } else if (v >= markerMax) { col = ColorGradientHelper.getGradientColor(0f, Color.RED, Color.GREEN); } c.setBackground(col); return c; }
Example 3
Source File: CustomizedTable.java From DeconvolutionLab2 with GNU General Public License v3.0 | 5 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) { DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); Component c = renderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col); if (value instanceof Double) { String s = NumFormat.nice(((Double) value).doubleValue()); c = renderer.getTableCellRendererComponent(table, s, isSelected, hasFocus, row, col); ((JLabel) c).setHorizontalAlignment(SwingConstants.RIGHT); } return c; }
Example 4
Source File: MosaicExpressionsPanel.java From snap-desktop with GNU General Public License v3.0 | 3 votes |
/** * Sets an initial <code>value</code> for the editor. This will cause the editor to <code>stopEditing</code> * and lose any partially edited value if the editor is editing when this method is called. <p> * <p> * Returns the component that should be added to the client's <code>Component</code> hierarchy. Once installed * in the client's hierarchy this component will then be able to draw and receive user input. * * @param table the <code>JTable</code> that is asking the editor to edit; can be <code>null</code> * @param value the value of the cell to be edited; it is up to the specific editor to interpret and draw the * value. For example, if value is the string "true", it could be rendered as a string or it could be rendered * as a check box that is checked. <code>null</code> is a valid value * @param isSelected true if the cell is to be rendered with highlighting * @param row the row of the cell being edited * @param column the column of the cell being edited * @return the component for editing */ @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { final JPanel renderPanel = new JPanel(new BorderLayout()); final DefaultTableCellRenderer defaultRenderer = new DefaultTableCellRenderer(); final Component label = defaultRenderer.getTableCellRendererComponent(table, value, isSelected, false, row, column); renderPanel.add(label); renderPanel.add(button, BorderLayout.EAST); this.value[0] = (String) value; return renderPanel; }