Java Code Examples for javax.swing.table.TableColumn#getWidth()

The following examples show how to use javax.swing.table.TableColumn#getWidth() . 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: ItemListImageViewerEvent.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adjust the column widths of a table based on the table contents.
 *
 * @param table adjusted table
 */
private void adjustColumnWidths(JTable table) {
	TableColumnModel model = table.getColumnModel();
	for (int column = 0; column < table.getColumnCount(); column++) {
		TableColumn tc = model.getColumn(column);
		int width = tc.getWidth();
		for (int row = 0; row < table.getRowCount(); row++) {
			Component comp = table.prepareRenderer(table.getCellRenderer(row, column), row, column);
			width = Math.max(width, comp.getPreferredSize().width);
		}

		tc.setPreferredWidth(width);
	}
}
 
Example 2
Source File: DarculaTableHeaderUI.java    From Darcula with Apache License 2.0 5 votes vote down vote up
@Override
public void paint(Graphics g2, JComponent c) {
  final Graphics2D g = (Graphics2D)g2;
  final GraphicsConfig config = new GraphicsConfig(g);
  final Color bg = c.getBackground();
  g.setPaint(new GradientPaint(0, 0, ColorUtil.shift(bg, 1.4), 0, c.getHeight(), ColorUtil.shift(bg, 0.9)));
  final int h = c.getHeight();
  final int w = c.getWidth();
  g.fillRect(0,0, w, h);
  g.setPaint(ColorUtil.shift(bg, 0.75));
  g.drawLine(0, h-1, w, h-1);
  g.drawLine(w-1, 0, w-1, h-1);

  final Enumeration<TableColumn> columns = ((JTableHeader)c).getColumnModel().getColumns();

  final Color lineColor = ColorUtil.shift(bg, 0.7);
  final Color shadow = Gray._255.withAlpha(30);
  int offset = 0;
  while (columns.hasMoreElements()) {
    final TableColumn column = columns.nextElement();
    if (columns.hasMoreElements() && column.getWidth() > 0) {
      offset += column.getWidth();
      g.setColor(lineColor);
      g.drawLine(offset-1, 1, offset-1, h-3);
      g.setColor(shadow);
      g.drawLine(offset, 1, offset, h-3);
    }
  }

  config.restore();

  super.paint(g, c);
}
 
Example 3
Source File: FrameBox.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
public static void fitTableToLastColumn(JTable tab) {
	TableColumnModel model = tab.getColumnModel();
	TableColumn lastCol = model.getColumn(model.getColumnCount() - 1);

	int delta = tab.getSize().width;
	for(int i = 0; i < model.getColumnCount(); i++) {
		delta -= model.getColumn(i).getWidth();
	}
	int newWidth = lastCol.getWidth() + delta;
	lastCol.setWidth(newWidth);
}
 
Example 4
Source File: JXTableDecorator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void drawVerticalLines(Graphics g, final int rowCount, final int height) {

        g.setColor(ResultSetJXTable.GRID_COLOR);
        TableColumnModel colModel = getColumnModel();
        int x = 0;
        for (int i = 0; i < colModel.getColumnCount(); ++i) {
            TableColumn column = colModel.getColumn(i);
            x += column.getWidth();
            g.drawLine(x - 1, rowCount * rowHeight, x - 1, height);
        }
    }
 
Example 5
Source File: ProfilerColumnModel.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
TableColumn createTableColumn(int columnIndex) {
    return new TableColumn(columnIndex) {
        public void setWidth(int width) {
            if (getMaxWidth() == 0 && getWidth() == 0) {
                TableColumn c = getPreviousVisibleColumn(this);
                if (refWidth == -1) refWidth = c.getWidth();
                c.setWidth(refWidth + width);
            } else {
                super.setWidth(width);
            }
        }                
    };
}
 
Example 6
Source File: EditableHeaderTableColumn.java    From chipster with MIT License 5 votes vote down vote up
public void copyValues(TableColumn base) {    
	modelIndex     = base.getModelIndex();
	identifier     = base.getIdentifier();
	width          = base.getWidth();
	minWidth       = base.getMinWidth();
	setPreferredWidth(base.getPreferredWidth());
	maxWidth       = base.getMaxWidth();
	headerRenderer = base.getHeaderRenderer();
	headerValue    = base.getHeaderValue();
	cellRenderer   = base.getCellRenderer();
	cellEditor     = base.getCellEditor();
	isResizable    = base.getResizable();
}
 
Example 7
Source File: SynthTableUI.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void paintCells(SynthContext context, Graphics g, int rMin,
                        int rMax, int cMin, int cMax) {
    JTableHeader header = table.getTableHeader();
    TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();

    TableColumnModel cm = table.getColumnModel();
    int columnMargin = cm.getColumnMargin();

    Rectangle cellRect;
    TableColumn aColumn;
    int columnWidth;
    if (table.getComponentOrientation().isLeftToRight()) {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            for(int column = cMin; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
                cellRect.x += columnWidth;
            }
        }
    } else {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            aColumn = cm.getColumn(cMin);
            if (aColumn != draggedColumn) {
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                paintCell(context, g, cellRect, row, cMin);
            }
            for(int column = cMin+1; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                cellRect.x -= columnWidth;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
            }
        }
    }

    // Paint the dragged column if we are dragging.
    if (draggedColumn != null) {
        paintDraggedArea(context, g, rMin, rMax, draggedColumn, header.getDraggedDistance());
    }

    // Remove any renderers that may be left in the rendererPane.
    rendererPane.removeAll();
}
 
Example 8
Source File: SynthTableUI.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private void paintCells(SynthContext context, Graphics g, int rMin,
                        int rMax, int cMin, int cMax) {
    JTableHeader header = table.getTableHeader();
    TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();

    TableColumnModel cm = table.getColumnModel();
    int columnMargin = cm.getColumnMargin();

    Rectangle cellRect;
    TableColumn aColumn;
    int columnWidth;
    if (table.getComponentOrientation().isLeftToRight()) {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            for(int column = cMin; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
                cellRect.x += columnWidth;
            }
        }
    } else {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            aColumn = cm.getColumn(cMin);
            if (aColumn != draggedColumn) {
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                paintCell(context, g, cellRect, row, cMin);
            }
            for(int column = cMin+1; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                cellRect.x -= columnWidth;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
            }
        }
    }

    // Paint the dragged column if we are dragging.
    if (draggedColumn != null) {
        paintDraggedArea(context, g, rMin, rMax, draggedColumn, header.getDraggedDistance());
    }

    // Remove any renderers that may be left in the rendererPane.
    rendererPane.removeAll();
}
 
Example 9
Source File: SynthTableUI.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void paintCells(SynthContext context, Graphics g, int rMin,
                        int rMax, int cMin, int cMax) {
    JTableHeader header = table.getTableHeader();
    TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();

    TableColumnModel cm = table.getColumnModel();
    int columnMargin = cm.getColumnMargin();

    Rectangle cellRect;
    TableColumn aColumn;
    int columnWidth;
    if (table.getComponentOrientation().isLeftToRight()) {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            for(int column = cMin; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
                cellRect.x += columnWidth;
            }
        }
    } else {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            aColumn = cm.getColumn(cMin);
            if (aColumn != draggedColumn) {
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                paintCell(context, g, cellRect, row, cMin);
            }
            for(int column = cMin+1; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                cellRect.x -= columnWidth;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
            }
        }
    }

    // Paint the dragged column if we are dragging.
    if (draggedColumn != null) {
        paintDraggedArea(context, g, rMin, rMax, draggedColumn, header.getDraggedDistance());
    }

    // Remove any renderers that may be left in the rendererPane.
    rendererPane.removeAll();
}
 
Example 10
Source File: SynthTableUI.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
private void paintCells(SynthContext context, Graphics g, int rMin,
                        int rMax, int cMin, int cMax) {
    JTableHeader header = table.getTableHeader();
    TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();

    TableColumnModel cm = table.getColumnModel();
    int columnMargin = cm.getColumnMargin();

    Rectangle cellRect;
    TableColumn aColumn;
    int columnWidth;
    if (table.getComponentOrientation().isLeftToRight()) {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            for(int column = cMin; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
                cellRect.x += columnWidth;
            }
        }
    } else {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            aColumn = cm.getColumn(cMin);
            if (aColumn != draggedColumn) {
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                paintCell(context, g, cellRect, row, cMin);
            }
            for(int column = cMin+1; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                cellRect.x -= columnWidth;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
            }
        }
    }

    // Paint the dragged column if we are dragging.
    if (draggedColumn != null) {
        paintDraggedArea(context, g, rMin, rMax, draggedColumn, header.getDraggedDistance());
    }

    // Remove any renderers that may be left in the rendererPane.
    rendererPane.removeAll();
}
 
Example 11
Source File: QuicklookProvider.java    From snap-desktop with GNU General Public License v3.0 4 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) {
    try {
        if (tableComponent == null) {
            tableComponent = (JLabel) super.getTableCellRendererComponent(table,
                    value,
                    isSelected,
                    hasFocus,
                    row,
                    column);
            tableComponent.setText("");
            tableComponent.setVerticalAlignment(SwingConstants.CENTER);
            tableComponent.setHorizontalAlignment(SwingConstants.CENTER);
        }

        setBackground(table, isSelected);

        if (value == null) {
            tableComponent.setIcon(null);
            tableComponent.setText("");
            return tableComponent;
        }

        if (value instanceof ProductEntry) {
            final BufferedImage image = getImage((ProductEntry) value);
            if (image == null) {
                tableComponent.setIcon(null);
                tableComponent.setText("Not available!");
            } else {
                final TableColumn tableColumn = table.getColumnModel().getColumn(column);
                int cellWidth = tableColumn.getWidth();
                int cellHeight = tableColumn.getWidth();
                if (image.getHeight() > image.getWidth())
                    cellWidth = -1;
                else
                    cellHeight = -1;
                tableComponent.setIcon(
                        new ImageIcon(image.getScaledInstance(cellWidth, cellHeight, BufferedImage.SCALE_FAST)));
                tableComponent.setText("");
                setTableRowHeight(table, row);
            }
        } else {
            tableComponent.setIcon(null);
        }
    } catch (Throwable e) {
        SystemUtils.LOG.severe("QuicklookRenderer: " + e.getMessage());
    }
    return tableComponent;
}
 
Example 12
Source File: SynthTableUI.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void paintCells(SynthContext context, Graphics g, int rMin,
                        int rMax, int cMin, int cMax) {
    JTableHeader header = table.getTableHeader();
    TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();

    TableColumnModel cm = table.getColumnModel();
    int columnMargin = cm.getColumnMargin();

    Rectangle cellRect;
    TableColumn aColumn;
    int columnWidth;
    if (table.getComponentOrientation().isLeftToRight()) {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            for(int column = cMin; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
                cellRect.x += columnWidth;
            }
        }
    } else {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            aColumn = cm.getColumn(cMin);
            if (aColumn != draggedColumn) {
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                paintCell(context, g, cellRect, row, cMin);
            }
            for(int column = cMin+1; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                cellRect.x -= columnWidth;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
            }
        }
    }

    // Paint the dragged column if we are dragging.
    if (draggedColumn != null) {
        paintDraggedArea(context, g, rMin, rMax, draggedColumn, header.getDraggedDistance());
    }

    // Remove any renderers that may be left in the rendererPane.
    rendererPane.removeAll();
}
 
Example 13
Source File: SynthTableUI.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void paintCells(SynthContext context, Graphics g, int rMin,
                        int rMax, int cMin, int cMax) {
    JTableHeader header = table.getTableHeader();
    TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();

    TableColumnModel cm = table.getColumnModel();
    int columnMargin = cm.getColumnMargin();

    Rectangle cellRect;
    TableColumn aColumn;
    int columnWidth;
    if (table.getComponentOrientation().isLeftToRight()) {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            for(int column = cMin; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
                cellRect.x += columnWidth;
            }
        }
    } else {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            aColumn = cm.getColumn(cMin);
            if (aColumn != draggedColumn) {
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                paintCell(context, g, cellRect, row, cMin);
            }
            for(int column = cMin+1; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                cellRect.x -= columnWidth;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
            }
        }
    }

    // Paint the dragged column if we are dragging.
    if (draggedColumn != null) {
        paintDraggedArea(context, g, rMin, rMax, draggedColumn, header.getDraggedDistance());
    }

    // Remove any renderers that may be left in the rendererPane.
    rendererPane.removeAll();
}
 
Example 14
Source File: ProfilerTable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void doLayout() {
    ProfilerColumnModel cModel = _getColumnModel();
    JTableHeader header = getTableHeader();
    TableColumn res = header == null ? null : header.getResizingColumn();
    if (res != null) {
        // Resizing column
        int delta = getWidth() - cModel.getTotalColumnWidth();
        TableColumn next = cModel.getNextVisibleColumn(res);
        if (res == next) {
            res.setWidth(res.getWidth() + delta);
        } else {
            next.setWidth(next.getWidth() + delta);
        }
    } else {
        // Resizing table
        int toResizeIndex = cModel.getFitWidthColumn();
        if (toResizeIndex == -1) {
            super.doLayout();
        } else {
            Enumeration<TableColumn> columns = cModel.getColumns();
            TableColumn toResizeColumn = null;
            int columnsWidth = 0;
            while (columns.hasMoreElements()) {
                TableColumn column = columns.nextElement();
                if (column.getModelIndex() == toResizeIndex) {
                    if (!cModel.isColumnVisible(column)) {
                        super.doLayout();
                        return;
                    }
                    toResizeColumn = column;
                } else {
                    columnsWidth += column.getWidth();
                }
            }
            if (toResizeColumn != null) toResizeColumn.setWidth(getWidth() - columnsWidth);

            // instead of super.doLayout()
            layout();
        }
    }
}
 
Example 15
Source File: TaskListTableUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
    * (copy & paste from BasicTableUI)
    */
   private void paintCells(Graphics g, int rMin, int rMax, int cMin, int cMax) {
JTableHeader header = table.getTableHeader();
TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();

TableColumnModel cm = table.getColumnModel();
int columnMargin = cm.getColumnMargin();

       Rectangle cellRect;
TableColumn aColumn;
int columnWidth;
if (table.getComponentOrientation().isLeftToRight()) {
    for(int row = rMin; row <= rMax; row++) {
	cellRect = table.getCellRect(row, cMin, false);
               if( isFoldingRow( row ) ) {
                   //paint the cell across the whole table
                   cellRect.x = 0;
                   cellRect.width = table.getColumnModel().getTotalColumnWidth()-columnMargin;
                   paintCell( g, cellRect, row, 0 );
               } else {
                   for(int column = cMin; column <= cMax; column++) {
                       aColumn = cm.getColumn(column);
                       columnWidth = aColumn.getWidth();
                       cellRect.width = columnWidth - columnMargin;
                       if (aColumn != draggedColumn) {
                           paintCell(g, cellRect, row, column);
                       }
                       cellRect.x += columnWidth;
                   }
               }
    }
} else {
    for(int row = rMin; row <= rMax; row++) {
               cellRect = table.getCellRect(row, cMin, false);
               if( isFoldingRow( row ) ) {
                   //paint the cell across the whole table
                   cellRect.x = 0;
                   cellRect.width = table.getColumnModel().getTotalColumnWidth()-columnMargin;
                   paintCell( g, cellRect, row, 0 );
               } else {
                   aColumn = cm.getColumn(cMin);
                   if (aColumn != draggedColumn) {
                       columnWidth = aColumn.getWidth();
                       cellRect.width = columnWidth - columnMargin;
                       paintCell(g, cellRect, row, cMin);
                   }
                   for(int column = cMin+1; column <= cMax; column++) {
                       aColumn = cm.getColumn(column);
                       columnWidth = aColumn.getWidth();
                       cellRect.width = columnWidth - columnMargin;
                       cellRect.x -= columnWidth;
                       if (aColumn != draggedColumn) {
                           paintCell(g, cellRect, row, column);
                       }
                   }
               }
    }
}

       // Paint the dragged column if we are dragging.
       if (draggedColumn != null) {
    paintDraggedArea(g, rMin, rMax, draggedColumn, header.getDraggedDistance());
}

// Remove any renderers that may be left in the rendererPane.
rendererPane.removeAll();
   }
 
Example 16
Source File: SynthTableUI.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void paintCells(SynthContext context, Graphics g, int rMin,
                        int rMax, int cMin, int cMax) {
    JTableHeader header = table.getTableHeader();
    TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();

    TableColumnModel cm = table.getColumnModel();
    int columnMargin = cm.getColumnMargin();

    Rectangle cellRect;
    TableColumn aColumn;
    int columnWidth;
    if (table.getComponentOrientation().isLeftToRight()) {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            for(int column = cMin; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
                cellRect.x += columnWidth;
            }
        }
    } else {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            aColumn = cm.getColumn(cMin);
            if (aColumn != draggedColumn) {
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                paintCell(context, g, cellRect, row, cMin);
            }
            for(int column = cMin+1; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                cellRect.x -= columnWidth;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
            }
        }
    }

    // Paint the dragged column if we are dragging.
    if (draggedColumn != null) {
        paintDraggedArea(context, g, rMin, rMax, draggedColumn, header.getDraggedDistance());
    }

    // Remove any renderers that may be left in the rendererPane.
    rendererPane.removeAll();
}
 
Example 17
Source File: SynthTableUI.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void paintCells(SynthContext context, Graphics g, int rMin,
                        int rMax, int cMin, int cMax) {
    JTableHeader header = table.getTableHeader();
    TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn();

    TableColumnModel cm = table.getColumnModel();
    int columnMargin = cm.getColumnMargin();

    Rectangle cellRect;
    TableColumn aColumn;
    int columnWidth;
    if (table.getComponentOrientation().isLeftToRight()) {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            for(int column = cMin; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
                cellRect.x += columnWidth;
            }
        }
    } else {
        for(int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            aColumn = cm.getColumn(cMin);
            if (aColumn != draggedColumn) {
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                paintCell(context, g, cellRect, row, cMin);
            }
            for(int column = cMin+1; column <= cMax; column++) {
                aColumn = cm.getColumn(column);
                columnWidth = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                cellRect.x -= columnWidth;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
            }
        }
    }

    // Paint the dragged column if we are dragging.
    if (draggedColumn != null) {
        paintDraggedArea(context, g, rMin, rMax, draggedColumn, header.getDraggedDistance());
    }

    // Remove any renderers that may be left in the rendererPane.
    rendererPane.removeAll();
}
 
Example 18
Source File: GraphTableController.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void showTooltip(int row) {
  TableColumn rootColumn = myTable.getColumnModel().getColumn(GraphTableModel.ROOT_COLUMN);
  Point point = new Point(rootColumn.getWidth() + myCommitRenderer.getTooltipXCoordinate(row),
                          row * myTable.getRowHeight() + myTable.getRowHeight() / 2);
  showTooltip(row, GraphTableModel.COMMIT_COLUMN, point, true);
}
 
Example 19
Source File: SeaGlassTableUI.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * Paint cells.
 *
 * @param context DOCUMENT ME!
 * @param g       DOCUMENT ME!
 * @param rMin    DOCUMENT ME!
 * @param rMax    DOCUMENT ME!
 * @param cMin    DOCUMENT ME!
 * @param cMax    DOCUMENT ME!
 */
private void paintCells(SeaGlassContext context, Graphics g, int rMin, int rMax, int cMin, int cMax) {
    JTableHeader header        = table.getTableHeader();
    TableColumn  draggedColumn = (header == null) ? null : header.getDraggedColumn();

    TableColumnModel cm           = table.getColumnModel();
    int              columnMargin = cm.getColumnMargin();

    Rectangle   cellRect;
    TableColumn aColumn;
    int         columnWidth;

    if (table.getComponentOrientation().isLeftToRight()) {
        for (int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            for (int column = cMin; column <= cMax; column++) {
                aColumn        = cm.getColumn(column);
                columnWidth    = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }

                cellRect.x += columnWidth;
            }
        }
    } else {
        for (int row = rMin; row <= rMax; row++) {
            cellRect = table.getCellRect(row, cMin, false);
            aColumn  = cm.getColumn(cMin);
            if (aColumn != draggedColumn) {
                columnWidth    = aColumn.getWidth();
                cellRect.width = columnWidth - columnMargin;
                paintCell(context, g, cellRect, row, cMin);
            }

            for (int column = cMin + 1; column <= cMax; column++) {
                aColumn        =  cm.getColumn(column);
                columnWidth    =  aColumn.getWidth();
                cellRect.width =  columnWidth - columnMargin;
                cellRect.x     -= columnWidth;
                if (aColumn != draggedColumn) {
                    paintCell(context, g, cellRect, row, column);
                }
            }
        }
    }

    // Paint the dragged column if we are dragging.
    if (draggedColumn != null) {
        paintDraggedArea(context, g, rMin, rMax, draggedColumn, header.getDraggedDistance());
    }

    // Remove any renderers that may be left in the rendererPane.
    rendererPane.removeAll();
}
 
Example 20
Source File: SwingXTableSettings.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public boolean saveSettings(Element element) {
    element.addAttribute("horizontalScroll", String.valueOf(table.isHorizontalScrollEnabled()));

    saveFontPreferences(element);

    Element columnsElem = element.element("columns");
    if (columnsElem != null) {
        element.remove(columnsElem);
    }
    columnsElem = element.addElement("columns");

    final List<TableColumn> visibleTableColumns = table.getColumns();
    final List<Table.Column> visibleColumns = new ArrayList<>();
    for (TableColumn tableColumn : visibleTableColumns) {
        visibleColumns.add((Table.Column) tableColumn.getIdentifier());
    }

    List<TableColumn> columns = table.getColumns(true);
    Collections.sort(
            columns,
            new Comparator<TableColumn>() {
                @SuppressWarnings("SuspiciousMethodCalls")
                @Override
                public int compare(TableColumn col1, TableColumn col2) {
                    if (col1 instanceof TableColumnExt && !((TableColumnExt) col1).isVisible()) {
                        return 1;
                    }
                    if (col2 instanceof TableColumnExt && !((TableColumnExt) col2).isVisible()) {
                        return -1;
                    }
                    int i1 = visibleColumns.indexOf(col1.getIdentifier());
                    int i2 = visibleColumns.indexOf(col2.getIdentifier());
                    return Integer.compare(i1, i2);
                }
            }
    );

    for (TableColumn column : columns) {
        Element colElem = columnsElem.addElement("column");
        colElem.addAttribute("id", column.getIdentifier().toString());

        int width = column.getWidth();
        colElem.addAttribute("width", String.valueOf(width));

        if (column instanceof TableColumnExt) {
            Boolean visible = ((TableColumnExt) column).isVisible();
            colElem.addAttribute("visible", visible.toString());
        }
    }

    if (table.getRowSorter() != null) {
        TableColumn sortedColumn = table.getSortedColumn();
        List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys();
        if (sortedColumn != null && !sortKeys.isEmpty()) {
            columnsElem.addAttribute("sortColumn", String.valueOf(sortedColumn.getIdentifier()));
            columnsElem.addAttribute("sortOrder", sortKeys.get(0).getSortOrder().toString());
        }
    }

    return true;
}