Java Code Examples for javax.swing.table.TableCellRenderer#getTableCellRendererComponent()
The following examples show how to use
javax.swing.table.TableCellRenderer#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: CompositeGhidraTableCellRenderer.java From ghidra with Apache License 2.0 | 6 votes |
@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 2
Source File: SwingUtilities2.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * 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 3
Source File: SwingUtilities2.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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 4
Source File: SwingUtilities2.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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: GroupableTableHeaderUI.java From mzmine3 with GNU General Public License v2.0 | 6 votes |
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 6
Source File: DarkTableCellRendererDelegate.java From darklaf with MIT License | 6 votes |
@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 7
Source File: GroupableTableHeaderUI.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
private void paintCell(Graphics g, Rectangle cellRect, int columnIndex) { TableColumn aColumn = header.getColumnModel().getColumn(columnIndex); TableCellRenderer renderer = aColumn.getHeaderRenderer(); if (renderer == null) renderer = header.getDefaultRenderer(); Component component = renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false, false, -1, columnIndex); rendererPane.add(component); rendererPane.paintComponent(g, component, header, cellRect.x, cellRect.y, cellRect.width, cellRect.height, true); }
Example 8
Source File: GroupableTableHeaderUI.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
private void paintCell(Graphics g, Rectangle cellRect, ColumnGroup cGroup) { TableCellRenderer renderer = cGroup.getHeaderRenderer(); Component component = renderer.getTableCellRendererComponent(header.getTable(), cGroup.getHeaderValue(), false, false, -1, -1); rendererPane.add(component); rendererPane.paintComponent(g, component, header, cellRect.x, cellRect.y, cellRect.width, cellRect.height, true); }
Example 9
Source File: FlatTableHeaderUI.java From FlatLaf with Apache License 2.0 | 5 votes |
@Override public void paint( Graphics g, JComponent c ) { // do not paint borders if JTableHeader.setDefaultRenderer() was used TableCellRenderer defaultRenderer = header.getDefaultRenderer(); boolean paintBorders = isSystemDefaultRenderer( defaultRenderer ); if( !paintBorders && header.getColumnModel().getColumnCount() > 0 ) { // check whether the renderer delegates to the system default renderer Component rendererComponent = defaultRenderer.getTableCellRendererComponent( header.getTable(), "", false, false, -1, 0 ); paintBorders = isSystemDefaultRenderer( rendererComponent ); } if( paintBorders ) paintColumnBorders( g, c ); // temporary use own default renderer if necessary FlatTableCellHeaderRenderer sortIconRenderer = null; if( sortIconPosition != SwingConstants.RIGHT ) { sortIconRenderer = new FlatTableCellHeaderRenderer( header.getDefaultRenderer() ); header.setDefaultRenderer( sortIconRenderer ); } // paint header super.paint( g, c ); // restore default renderer if( sortIconRenderer != null ) { sortIconRenderer.reset(); header.setDefaultRenderer( sortIconRenderer.delegate ); } if( paintBorders ) paintDraggedColumnBorders( g, c ); }
Example 10
Source File: bug7032791.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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 11
Source File: ColumnWidthsResizer.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 12
Source File: bug7032791.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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 13
Source File: bug7032791.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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 14
Source File: bug7032791.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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 15
Source File: VariationPerParameterTableController.java From OpenDA with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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)); } }
Example 16
Source File: CorrelationTableController.java From OpenDA with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 17
Source File: SubstanceTableHeaderUI.java From radiance with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void uninstallUI(JComponent c) { for (int i = 0; i < header.getColumnModel().getColumnCount(); i++) { TableColumn aColumn = header.getColumnModel().getColumn(i); TableCellRenderer renderer = aColumn.getHeaderRenderer(); if (renderer == null) { renderer = header.getDefaultRenderer(); } Component rendComp = renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false, false, -1, i); SwingUtilities.updateComponentTreeUI(rendComp); } super.uninstallUI(c); }
Example 18
Source File: ResultsTableController.java From OpenDA with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 19
Source File: ColumnWidthsResizer.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static int getCellWidth(JTable table, int rowViewIndex, int colViewIndex) { TableCellRenderer cellRenderer = table.getCellRenderer(rowViewIndex, colViewIndex); Object value = table.getValueAt(rowViewIndex, colViewIndex); Component cellRendererComp = cellRenderer.getTableCellRendererComponent(table, value, false, false, rowViewIndex, colViewIndex); return cellRendererComp.getPreferredSize().width; }
Example 20
Source File: PeakListTableWindow.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
/** * Methods for ActionListener interface implementation */ @Override public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (command.equals("PROPERTIES")) { ExitCode exitCode = parameters.showSetupDialog(true); if (exitCode == ExitCode.OK) { int rowHeight = parameters.getParameter(PeakListTableParameters.rowHeight).getValue(); table.setRowHeight(rowHeight); PeakListTableColumnModel cm = (PeakListTableColumnModel) table.getColumnModel(); cm.createColumns(); } } if (command.equals("AUTOCOLUMNWIDTH")) { // Auto size column width based on data for (int column = 0; column < table.getColumnCount(); column++) { TableColumn tableColumn = table.getColumnModel().getColumn(column); if (tableColumn.getHeaderValue() != "Peak shape" && tableColumn.getHeaderValue() != "Status") { TableCellRenderer renderer = tableColumn.getHeaderRenderer(); if (renderer == null) { renderer = table.getTableHeader().getDefaultRenderer(); } Component component = renderer.getTableCellRendererComponent(table, tableColumn.getHeaderValue(), false, false, -1, column); int preferredWidth = component.getPreferredSize().width + 20; tableColumn.setPreferredWidth(preferredWidth); } } } if (command.equals("PRINT")) { try { table.print(PrintMode.FIT_WIDTH); } catch (PrinterException e) { MZmineCore.getDesktop().displayException(e); } } }