use of javax.swing.table.TableCellRenderer in project adempiere by adempiere.
the class POSDefaultCellEditor method getTableCellEditorComponent.
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
delegate.setValue(value);
if (editorComponent instanceof JButton) {
//in order to avoid a "flashing" effect when clicking a checkbox
//in a table, it is important for the editor to have as a border
//the same border that the renderer has, and have as the background
//the same color as the renderer has. This is primarily only
//needed for JCheckBox since this editor doesn't fill all the
//visual space of the table cell, unlike a text field.
TableCellRenderer renderer = table.getCellRenderer(row, column);
Component c = renderer.getTableCellRendererComponent(table, value, isSelected, true, row, column);
if (c != null) {
editorComponent.setOpaque(true);
editorComponent.setBackground(c.getBackground());
if (c instanceof JComponent) {
editorComponent.setBorder(((JComponent) c).getBorder());
}
} else {
editorComponent.setOpaque(false);
}
}
return editorComponent;
}
use of javax.swing.table.TableCellRenderer in project pcgen by PCGen.
the class AutoSizingColumnModel method setColumnPreferredWidth.
/**
* Set preffered column width
* @param aColumn
*/
public void setColumnPreferredWidth(TableColumn aColumn) {
if (m_table != null) {
TableCellRenderer renderer = null;
int rowCount = m_table.getRowCount();
int headerWidth = 0;
int contentsWidth = 0;
if (aColumn.getHeaderRenderer() != null) {
renderer = aColumn.getHeaderRenderer();
} else {
renderer = m_table.getTableHeader().getDefaultRenderer();
}
if (renderer != null) {
headerWidth = renderer.getTableCellRendererComponent(m_table, aColumn.getHeaderValue(), false, false, 0, 0).getPreferredSize().width;
}
renderer = m_table.getDefaultRenderer(m_table.getModel().getColumnClass(getColumnCount()));
if (renderer != null && getColumnCount() > 0) {
for (int row = 0; row < rowCount; row++) {
contentsWidth = Math.max(contentsWidth, renderer.getTableCellRendererComponent(m_table, m_table.getModel().getValueAt(row, getColumnCount()), false, false, row, 0).getPreferredSize().width);
}
}
aColumn.setPreferredWidth(Math.max(headerWidth, contentsWidth) + getColumnMargin() + COLUMN_WIDTH_PADDING);
} else {
aColumn.setPreferredWidth(150);
}
}
use of javax.swing.table.TableCellRenderer in project jdk8u_jdk by JetBrains.
the class SwingUtilities2 method pointOutsidePrefSize.
/**
* 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;
// 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;
}
use of javax.swing.table.TableCellRenderer in project jmeter by apache.
the class GuiUtils method fixSize.
/**
* Fix the size of a column according to the header text.
*
* @param column to be resized
* @param table containing the column
*/
public static void fixSize(TableColumn column, JTable table) {
TableCellRenderer rndr;
rndr = column.getHeaderRenderer();
if (rndr == null) {
rndr = table.getTableHeader().getDefaultRenderer();
}
Component c = rndr.getTableCellRendererComponent(table, column.getHeaderValue(), false, false, -1, column.getModelIndex());
int width = c.getPreferredSize().width + 10;
column.setMaxWidth(width);
column.setPreferredWidth(width);
column.setResizable(false);
}
use of javax.swing.table.TableCellRenderer in project jmeter by apache.
the class HeaderAsPropertyRendererWrapper method setupDefaultRenderer.
/**
* @param table {@link JTable}
* @param columnsMsgParameters Double dimension array of column message parameters
*/
public static void setupDefaultRenderer(JTable table, Object[][] columnsMsgParameters) {
TableCellRenderer defaultRenderer = table.getTableHeader().getDefaultRenderer();
HeaderAsPropertyRendererWrapper newRenderer = new HeaderAsPropertyRendererWrapper(defaultRenderer, columnsMsgParameters);
table.getTableHeader().setDefaultRenderer(newRenderer);
}
Aggregations