javax.swing.table.TableCellRenderer Java Examples

The following examples show how to use javax.swing.table.TableCellRenderer. 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: SwingUtilities2.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns true if the given point is outside the preferredSize of the
 * item at the given row of the table.  (Column must be 0).
 * Does not check the "Table.isFileList" property. That should be checked
 * before calling this method.
 * This is used to make WindowsL&F JFileChooser act like native dialogs.
 */
public static boolean pointOutsidePrefSize(JTable table, int row, int column, Point p) {
    if (table.convertColumnIndexToModel(column) != 0 || row == -1) {
        return true;
    }
    TableCellRenderer tcr = table.getCellRenderer(row, column);
    Object value = table.getValueAt(row, column);
    Component cell = tcr.getTableCellRendererComponent(table, value, false,
            false, row, column);
    Dimension itemSize = cell.getPreferredSize();
    Rectangle cellBounds = table.getCellRect(row, column, false);
    cellBounds.width = itemSize.width;
    cellBounds.height = itemSize.height;

    // See if coords are inside
    // ASSUME: mouse x,y will never be < cell's x,y
    assert (p.x >= cellBounds.x && p.y >= cellBounds.y);
    return p.x > cellBounds.x + cellBounds.width ||
            p.y > cellBounds.y + cellBounds.height;
}
 
Example #2
Source File: CompositeGhidraTableCellRenderer.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private TableCellRenderer getCellRenderer(JTable table, int row, int column) {

		// 
		// Step 1: See if we can use our custom rendering lookup        
		// 
		if (table instanceof GTable) {
			GTable gTable = (GTable) table;
			return gTable.getCellRendererOverride(row, column);
		}

		// 
		// Step 2: Locate normal JTable-style rendering   
		//
		TableColumn tableColumn = table.getColumnModel().getColumn(column);
		TableCellRenderer renderer = tableColumn.getCellRenderer();
		if (renderer == null) {
			renderer = table.getDefaultRenderer(table.getColumnClass(column));
		}
		return renderer;
	}
 
Example #3
Source File: EquateTablePluginTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddEquateReference() throws Exception {
	// add another equate reference; the reference count should update.

	Equate eq = equatesModel.getEquate(2);
	TableCellRenderer renderer = getRenderer(EquateTableModel.REFS_COL);
	String value = getRenderedValue(renderer, 2, EquateTableModel.REFS_COL);
	assertEquals("2", value);

	int transactionID = program.startTransaction("test");
	eq.addReference(getAddr(0x0100248c), 0);
	endTransaction(transactionID);

	value = getRenderedValue(renderer, 2, EquateTableModel.REFS_COL);
	assertEquals("3", value);

	undo();
	value = getRenderedValue(renderer, 2, EquateTableModel.REFS_COL);
	assertEquals("2", value);

	redo();
	value = getRenderedValue(renderer, 2, EquateTableModel.REFS_COL);
	assertEquals("3", value);
}
 
Example #4
Source File: SwingUtilities2.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns true if the given point is outside the preferredSize of the
 * item at the given row of the table.  (Column must be 0).
 * Does not check the "Table.isFileList" property. That should be checked
 * before calling this method.
 * This is used to make WindowsL&F JFileChooser act like native dialogs.
 */
public static boolean pointOutsidePrefSize(JTable table, int row, int column, Point p) {
    if (table.convertColumnIndexToModel(column) != 0 || row == -1) {
        return true;
    }
    TableCellRenderer tcr = table.getCellRenderer(row, column);
    Object value = table.getValueAt(row, column);
    Component cell = tcr.getTableCellRendererComponent(table, value, false,
            false, row, column);
    Dimension itemSize = cell.getPreferredSize();
    Rectangle cellBounds = table.getCellRect(row, column, false);
    cellBounds.width = itemSize.width;
    cellBounds.height = itemSize.height;

    // See if coords are inside
    // ASSUME: mouse x,y will never be < cell's x,y
    assert (p.x >= cellBounds.x && p.y >= cellBounds.y);
    return p.x > cellBounds.x + cellBounds.width ||
            p.y > cellBounds.y + cellBounds.height;
}
 
Example #5
Source File: EquateTablePluginTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveEquateReference() throws Exception {
	Equate eq = equatesModel.getEquate(3);

	int transactionID = program.startTransaction("test");
	// remove an equate reference; the reference count should update.
	eq.removeReference(getAddr(0x0100621d), 1);
	endTransaction(transactionID);

	TableCellRenderer renderer = getRenderer(EquateTableModel.REFS_COL);
	String value = getRenderedValue(renderer, 3, EquateTableModel.REFS_COL);
	assertEquals("3", value);

	undo();
	value = getRenderedValue(renderer, 3, EquateTableModel.REFS_COL);
	assertEquals("4", value);

	redo();
	value = getRenderedValue(renderer, 3, EquateTableModel.REFS_COL);
	assertEquals("3", value);
}
 
Example #6
Source File: GroupableTableHeaderUI.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
private int getHeaderHeight() {
  int height = 0;
  TableColumnModel columnModel = header.getColumnModel();
  for (int column = 0; column < columnModel.getColumnCount(); column++) {
    TableColumn aColumn = columnModel.getColumn(column);
    TableCellRenderer renderer = aColumn.getHeaderRenderer();
    if (renderer == null)
      renderer = header.getDefaultRenderer();
    Component comp = renderer.getTableCellRendererComponent(header.getTable(),
        aColumn.getHeaderValue(), false, false, -1, column);
    int cHeight = comp.getPreferredSize().height;
    Enumeration<?> en = ((GroupableTableHeader) header).getColumnGroups(aColumn);
    if (en != null) {
      while (en.hasMoreElements()) {
        ColumnGroup cGroup = (ColumnGroup) en.nextElement();
        cHeight += cGroup.getSize(header.getTable()).height;
      }
    }
    height = Math.max(height, cHeight);
  }
  return height;
}
 
Example #7
Source File: CompositeGhidraTableCellRenderer.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public Component getTableCellRendererComponent(GTableCellRenderingData data) {

	Object value = data.getValue();
	JTable table = data.getTable();
	int row = data.getRowViewIndex();
	int column = data.getColumnViewIndex();
	boolean isSelected = data.isSelected();
	boolean hasFocus = data.hasFocus();

	Component rendererComponent = null;
	TableCellRenderer cellRenderer = getCellRenderer(table, row, column);
	if (cellRenderer != null) {
		rendererComponent =
			cellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
				column);
	}
	else {
		// no defined renderer; use me
		rendererComponent =
			super.getTableCellRendererComponent(data);
	}

	return rendererComponent;
}
 
Example #8
Source File: SwingUtilities2.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns true if the given point is outside the preferredSize of the
 * item at the given row of the table.  (Column must be 0).
 * Does not check the "Table.isFileList" property. That should be checked
 * before calling this method.
 * This is used to make WindowsL&F JFileChooser act like native dialogs.
 */
public static boolean pointOutsidePrefSize(JTable table, int row, int column, Point p) {
    if (table.convertColumnIndexToModel(column) != 0 || row == -1) {
        return true;
    }
    TableCellRenderer tcr = table.getCellRenderer(row, column);
    Object value = table.getValueAt(row, column);
    Component cell = tcr.getTableCellRendererComponent(table, value, false,
            false, row, column);
    Dimension itemSize = cell.getPreferredSize();
    Rectangle cellBounds = table.getCellRect(row, column, false);
    cellBounds.width = itemSize.width;
    cellBounds.height = itemSize.height;

    // See if coords are inside
    // ASSUME: mouse x,y will never be < cell's x,y
    assert (p.x >= cellBounds.x && p.y >= cellBounds.y);
    return p.x > cellBounds.x + cellBounds.width ||
            p.y > cellBounds.y + cellBounds.height;
}
 
Example #9
Source File: OldJTable.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public TableColumn addColumn(Object columnIdentifier, int width,
                             TableCellRenderer renderer,
                             TableCellEditor editor, List columnData) {
    checkDefaultTableModel();

    // Set up the model side first
    DefaultTableModel m = (DefaultTableModel)getModel();
    m.addColumn(columnIdentifier, columnData.toArray());

    // The column will have been added to the end, so the index of the
    // column in the model is the last element.
    TableColumn newColumn = new TableColumn(
            m.getColumnCount()-1, width, renderer, editor);
    super.addColumn(newColumn);
    return newColumn;
}
 
Example #10
Source File: OldJTable.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public TableColumn addColumn(Object columnIdentifier, int width,
                             TableCellRenderer renderer,
                             TableCellEditor editor, List columnData) {
    checkDefaultTableModel();

    // Set up the model side first
    DefaultTableModel m = (DefaultTableModel)getModel();
    m.addColumn(columnIdentifier, columnData.toArray());

    // The column will have been added to the end, so the index of the
    // column in the model is the last element.
    TableColumn newColumn = new TableColumn(
            m.getColumnCount()-1, width, renderer, editor);
    super.addColumn(newColumn);
    return newColumn;
}
 
Example #11
Source File: PreviewTable.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Must override this in order for horizontal scrolling to work. Scrolling
 * isn't automatically given when embedding a jtable in a scrollpanel; the
 * preferred width of the table must be explicitly set to the width of the
 * contents of the widest cell.
 * 
 * Note: We could override getPreferredSize() instead but we don't want to
 * change the default behavior for setting the preferred height, only the
 * width. So it's better to do it here.
 */
@Override
public boolean getScrollableTracksViewportWidth() {

	// Loop over all cells, getting the width of the largest cell.
	int width = 0;
	for (int row = 0; row < getRowCount(); row++) {
		TableCellRenderer rendererr = getCellRenderer(row, 0);
		Component comp = prepareRenderer(rendererr, row, 0);
		width = Math.max(comp.getPreferredSize().width, width);
	}

	// Now set the new preferred size using that max width, and the
	// existing preferred height.
	this.setPreferredSize(new Dimension(width, getPreferredSize().height));

	// Return true if the viewport has changed such that the table columns need to 
	// be resized.
	return getPreferredSize().width < getParent().getWidth();
}
 
Example #12
Source File: XTable.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Component prepareRenderer(TableCellRenderer renderer,
                                 int row, int column) {
    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }

    if (column == VALUE_COLUMN && isAttributeViewable(row, VALUE_COLUMN)) {
        comp.setFont(boldFont);
    } else {
        comp.setFont(normalFont);
    }

    return comp;
}
 
Example #13
Source File: AbstractGenericTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the rendered value for the specified table cell.  The actual value at the cell may
 * not be a String.  This method will get the String display value, as created by the table.
 * 
 * @param table the table to query
 * @param row the row to query
 * @param column the column to query
 * @return the String value
 * @throws IllegalArgumentException if there is no renderer or the rendered component is
 *         something from which this method can get a String (such as a JLabel)
 */
public static String getRenderedTableCellValue(JTable table, int row, int column) {

	return runSwing(() -> {

		TableCellRenderer renderer = table.getCellRenderer(row, column);
		if (renderer == null) {
			throw new IllegalArgumentException(
				"No renderer registered for row/col: " + row + '/' + column);
		}
		Component component = table.prepareRenderer(renderer, row, column);
		if (!(component instanceof JLabel)) {
			throw new IllegalArgumentException(
				"Do not know how to get text from a renderer " + "that is not a JLabel");
		}

		return ((JLabel) component).getText();
	});
}
 
Example #14
Source File: XTable.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Component prepareRenderer(TableCellRenderer renderer,
                                 int row, int column) {
    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }

    if (column == VALUE_COLUMN && isAttributeViewable(row, VALUE_COLUMN)) {
        comp.setFont(boldFont);
    } else {
        comp.setFont(normalFont);
    }

    return comp;
}
 
Example #15
Source File: DarkTableCellRendererDelegate.java    From darklaf with MIT License 6 votes vote down vote up
@Override
public Component getTableCellRendererComponent(final JTable table, final Object value,
                                               final boolean isSelected, final boolean hasFocus,
                                               final int row, final int column) {
    TableCellRenderer renderer = TableConstants.useBooleanEditorForValue(value, table)
            ? getBooleanRenderer(table)
            : super.getDelegate();
    Component component = renderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

    boolean isRowFocus = DarkTableCellFocusBorder.isRowFocusBorder(table);
    boolean isLeadSelectionCell = DarkUIUtil.hasFocus(table) && hasFocus && !isRowFocus;
    boolean paintSelected = isSelected && !isLeadSelectionCell && !table.isEditing();

    if (component instanceof JComponent) {
        setupBorderStyle(table, row, column, (JComponent) component, isRowFocus);
    }
    CellUtil.setupTableForeground(component, table, paintSelected);
    CellUtil.setupTableBackground(component, table, paintSelected, row);
    return component;
}
 
Example #16
Source File: XTable.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Component prepareRenderer(TableCellRenderer renderer,
                                 int row, int column) {
    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }

    if (column == VALUE_COLUMN && isAttributeViewable(row, VALUE_COLUMN)) {
        comp.setFont(boldFont);
    } else {
        comp.setFont(normalFont);
    }

    return comp;
}
 
Example #17
Source File: XTable.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Component prepareRenderer(TableCellRenderer renderer,
                                 int row, int column) {
    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }

    if (column == VALUE_COLUMN && isAttributeViewable(row, VALUE_COLUMN)) {
        comp.setFont(boldFont);
    } else {
        comp.setFont(normalFont);
    }

    return comp;
}
 
Example #18
Source File: TableAligner.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Installs alignment decorators in the table column at {@code colViewIndex}.
 *
 * @param table a table.
 * @param colViewIndex the index of the column in the table <i>view</i>.
 * @param alignment one of the following constants:
 *        <ul>
 *        <li>{@link SwingConstants#LEFT}</li>
 *        <li>{@link SwingConstants#CENTER} (the default for image-only labels)</li>
 *        <li>{@link SwingConstants#RIGHT}</li>
 *        <li>{@link SwingConstants#LEADING} (the default for text-only labels)</li>
 *        <li>{@link SwingConstants#TRAILING}</li>
 *        </ul>
 */
public static void installInOneColumn(JTable table, int colViewIndex, int alignment) {
  TableColumn tableColumn = table.getColumnModel().getColumn(colViewIndex);

  TableCellRenderer headerRenderer = tableColumn.getHeaderRenderer();
  if (headerRenderer == null) {
    headerRenderer = table.getTableHeader().getDefaultRenderer();
  }
  if (!(headerRenderer instanceof RendererAlignmentDecorator)) { // Don't install a redundant decorator.
    tableColumn.setHeaderRenderer(new RendererAlignmentDecorator(headerRenderer, alignment));
  }

  TableCellRenderer cellRenderer = tableColumn.getCellRenderer();
  if (cellRenderer == null) {
    cellRenderer = table.getDefaultRenderer(table.getColumnClass(colViewIndex));
  }
  if (!(cellRenderer instanceof RendererAlignmentDecorator)) { // Don't install a redundant decorator.
    tableColumn.setCellRenderer(new RendererAlignmentDecorator(cellRenderer, alignment));
  }
}
 
Example #19
Source File: SynthTableUI.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private TableCellRenderer installRendererIfPossible(Class objectClass,
                                 TableCellRenderer renderer) {
    TableCellRenderer currentRenderer = table.getDefaultRenderer(
                             objectClass);
    if (currentRenderer instanceof UIResource) {
        table.setDefaultRenderer(objectClass, renderer);
    }
    return currentRenderer;
}
 
Example #20
Source File: XMBeanAttributes.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Component prepareRenderer(TableCellRenderer renderer,
                                              int row, int column) {
    //In case we have a repaint thread that is in the process of
    //repainting an obsolete table, just ignore the call.
    //It can happen when MBean selection is switched at a very quick rate
    if(row >= getRowCount())
        return null;
    else
        return super.prepareRenderer(renderer, row, column);
}
 
Example #21
Source File: CorrelationTableController.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * This method picks good column sizes. If all column headers are wider than
 * the column's cells' contents, then just use column.sizeWidthToFit().
    * @param table The correlation table
    */
public void initColumnSizes(JTable table) {

	TableColumn column;
	Component comp;
	int headerWidth;
	int cellWidth;

	TableCellRenderer headerRenderer = table.getTableHeader()
			.getDefaultRenderer();

	// TODO: move to tableModel. AK
	for (int i = 0; i < this.correlationTableModel.getColumnCount(); i++) {
		column = table.getColumnModel().getColumn(i);

		comp = headerRenderer.getTableCellRendererComponent(null, column
				.getHeaderValue(), false, false, 0, 0);
		headerWidth = comp.getPreferredSize().width;

		// /TODO: move to tableModel. AK
		comp = table.getDefaultRenderer(this.correlationTableModel.getColumnClass(i))
				.getTableCellRendererComponent(table, this.correlationTableModel.longValues[i], false,
						false, 0, i);
		cellWidth = comp.getPreferredSize().width;

		// XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
		column.setPreferredWidth(Math.max(headerWidth, cellWidth));
	}
}
 
Example #22
Source File: bug7032791.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        UIManager.setLookAndFeel(new SynthLookAndFeel());

        Object value = "Test value";
        JTable table = new JTable(1, 1);
        TableCellRenderer renderer = table.getDefaultRenderer(Object.class);
        renderer.getTableCellRendererComponent(null, value, true, true, 0, 0);
        System.out.println("OK");
    }
 
Example #23
Source File: ResultsTableController.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * This method picks good column sizes. If all column headers are wider than
 * the column's cells' contents, then just use column.sizeWidthToFit().
    * @param table Selected Results Table
    */
public void initColumnSizes(JTable table) {

	TableColumn column;
	Component comp;
	int headerWidth;
	int cellWidth;

	TableCellRenderer headerRenderer = table.getTableHeader()
			.getDefaultRenderer();

	// TODO: move to tableModel. AK
	for (int i = 0; i < this.resultsTableModel.getColumnCount(); i++) {
		column = table.getColumnModel().getColumn(i);

		comp = headerRenderer.getTableCellRendererComponent(null, column
				.getHeaderValue(), false, false, 0, 0);
		headerWidth = comp.getPreferredSize().width;

		// /TODO: move to tableModel. AK
		comp = table.getDefaultRenderer(this.resultsTableModel.getColumnClass(i))
				.getTableCellRendererComponent(table, this.resultsTableModel.longValues[i], false,
						false, 0, i);
		cellWidth = comp.getPreferredSize().width;

		// XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
		column.setPreferredWidth(Math.max(headerWidth, cellWidth));
	}
}
 
Example #24
Source File: EquateTablePluginTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void checkTableValues() throws Exception {
	Iterator<Equate> iter = et.getEquates();
	List<Equate> list = CollectionUtils.asList(iter);

	Collections.sort(list, (e1, e2) -> e1.getName().compareTo(e2.getName()));
	assertEquals(list.size(), equatesModel.getRowCount());

	TableCellRenderer nameRenderer = getRenderer(EquateTableModel.NAME_COL);
	TableCellRenderer valueRenderer = getRenderer(EquateTableModel.VALUE_COL);
	TableCellRenderer refCountRenderer = getRenderer(EquateTableModel.REFS_COL);

	for (int i = 0; i < list.size(); i++) {

		Equate eq = list.get(i);
		Rectangle rect = equatesTable.getCellRect(i, EquateTableModel.NAME_COL, true);
		runSwing(() -> equatesTable.scrollRectToVisible(rect));

		String value = getRenderedValue(nameRenderer, i, EquateTableModel.NAME_COL);
		assertEquals("Name not equal at index: " + i, eq.getName(), value);

		// The value column is default-rendered as hex
		value = getRenderedValue(valueRenderer, i, EquateTableModel.VALUE_COL);
		assertEquals("Value not equal at index: " + i, Long.toHexString(eq.getValue()) + "h",
			value);

		value = getRenderedValue(refCountRenderer, i, EquateTableModel.REFS_COL);
		assertEquals("Reference count not equal at index: " + i,
			Integer.toString(eq.getReferenceCount()), value);
	}
}
 
Example #25
Source File: ColumnWidthsResizer.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void resize(JTable table, int colViewIndex, boolean doFullScan) {
  int maxWidth = 0;

  // Get header width.
  TableColumn column = table.getColumnModel().getColumn(colViewIndex);
  TableCellRenderer headerRenderer = column.getHeaderRenderer();

  if (headerRenderer == null) {
    headerRenderer = table.getTableHeader().getDefaultRenderer();
  }

  Object headerValue = column.getHeaderValue();
  Component headerRendererComp =
      headerRenderer.getTableCellRendererComponent(table, headerValue, false, false, 0, colViewIndex);

  maxWidth = Math.max(maxWidth, headerRendererComp.getPreferredSize().width);


  // Get cell widths.
  if (doFullScan) {
    for (int row = 0; row < table.getRowCount(); ++row) {
      maxWidth = Math.max(maxWidth, getCellWidth(table, row, colViewIndex));
    }
  } else {
    maxWidth = Math.max(maxWidth, getCellWidth(table, 0, colViewIndex));
    maxWidth = Math.max(maxWidth, getCellWidth(table, table.getRowCount() / 2, colViewIndex));
    maxWidth = Math.max(maxWidth, getCellWidth(table, table.getRowCount() - 1, colViewIndex));
  }

  // For some reason, the calculation above gives a value that is 1 pixel too small.
  // Maybe that's because of the cell divider line?
  ++maxWidth;

  column.setPreferredWidth(maxWidth);
}
 
Example #26
Source File: bug7032791.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        UIManager.setLookAndFeel(new SynthLookAndFeel());

        Object value = "Test value";
        JTable table = new JTable(1, 1);
        TableCellRenderer renderer = table.getDefaultRenderer(Object.class);
        renderer.getTableCellRendererComponent(null, value, true, true, 0, 0);
        System.out.println("OK");
    }
 
Example #27
Source File: GTableAutoLookup.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public String getValueString(int row, int col) {
	TableCellRenderer renderer = table.getCellRenderer(row, col);
	if (renderer instanceof JLabel) {
		table.prepareRenderer(renderer, row, col);
		return ((JLabel) renderer).getText();
	}

	Object obj = table.getValueAt(row, col);
	return obj == null ? null : obj.toString();
}
 
Example #28
Source File: SynthTableUI.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private TableCellRenderer installRendererIfPossible(Class objectClass,
                                 TableCellRenderer renderer) {
    TableCellRenderer currentRenderer = table.getDefaultRenderer(
                             objectClass);
    if (currentRenderer instanceof UIResource) {
        table.setDefaultRenderer(objectClass, renderer);
    }
    return currentRenderer;
}
 
Example #29
Source File: DefaultTableCellRendererWrapper.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public DefaultTableCellRendererWrapper(TableCellRenderer renderer) {
	this.renderer = renderer;

	// we have to do this again here, as the super constructor called us back before we
	// set the 'renderer' variable
	setHTMLRenderingEnabled(false);
}
 
Example #30
Source File: VariationPerParameterTableController.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * This method picks good column sizes. If all column headers are wider than
 * the column's cells' contents, then just use column.sizeWidthToFit().
    * @param table  JTable
    */
public void initColumnSizes(JTable table) {

	TableColumn column;
	Component comp;
	int headerWidth;
	int cellWidth;

	TableCellRenderer headerRenderer = table.getTableHeader()
			.getDefaultRenderer();

	// TODO: move to tableModel. AK
	for (int i = 0; i < this.variationPerParameterTableModel.getColumnCount(); i++) {
		column = table.getColumnModel().getColumn(i);

		comp = headerRenderer.getTableCellRendererComponent(null, column
				.getHeaderValue(), false, false, 0, 0);
		headerWidth = comp.getPreferredSize().width;

		// /TODO: move to tableModel. AK
		comp = table.getDefaultRenderer(this.variationPerParameterTableModel.getColumnClass(i))
				.getTableCellRendererComponent(table, this.variationPerParameterTableModel.longValues[i], false,
						false, 0, i);
		cellWidth = comp.getPreferredSize().width;

		// XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
		column.setPreferredWidth(Math.max(headerWidth, cellWidth));
	}
}