Java Code Examples for javax.swing.table.JTableHeader#isPaintingForPrint()
The following examples show how to use
javax.swing.table.JTableHeader#isPaintingForPrint() .
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: DefaultTableHeaderRenderer.java From dsworkbench with Apache License 2.0 | 4 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Icon sortIcon = null; // setBackground(Constants.DS_BACK); boolean isPaintingForPrint = false; if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { Color fgColor = null; Color bgColor = null; if (hasFocus) { fgColor = UIManager.getColor("TableHeader.focusCellForeground"); bgColor = UIManager.getColor("TableHeader.focusCellBackground"); } if (fgColor == null) { fgColor = header.getForeground(); } if (bgColor == null) { bgColor = header.getBackground(); } setFont(header.getFont()); isPaintingForPrint = header.isPaintingForPrint(); } if (!isPaintingForPrint && table.getRowSorter() != null) { if (!horizontalTextPositionSet) { // There is a row sorter, and the developer hasn't // set a text position, change to leading. setHorizontalTextPosition(JLabel.LEADING); } java.util.List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys(); if (sortKeys.size() > 0 && sortKeys.get(0).getColumn() == table.convertColumnIndexToModel(column)) { switch (sortKeys.get(0).getSortOrder()) { case ASCENDING: sortIcon = UIManager.getIcon("Table.ascendingSortIcon"); break; case DESCENDING: sortIcon = UIManager.getIcon("Table.descendingSortIcon"); break; case UNSORTED: sortIcon = UIManager.getIcon("Table.naturalSortIcon"); break; } } } } setText(value == null ? "" : value.toString()); setIcon(sortIcon); Border border = null; if (hasFocus) { border = UIManager.getBorder("TableHeader.focusCellBorder"); } if (border == null) { border = UIManager.getBorder("TableHeader.cellBorder"); } setBorder(border); return this; }
Example 2
Source File: SupportTableHeaderRenderer.java From dsworkbench with Apache License 2.0 | 4 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Icon sortIcon = null; boolean isPaintingForPrint = false; if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { Color fgColor = null; Color bgColor = null; if (hasFocus) { fgColor = UIManager.getColor("TableHeader.focusCellForeground"); bgColor = UIManager.getColor("TableHeader.focusCellBackground"); } if (fgColor == null) { fgColor = header.getForeground(); } if (bgColor == null) { bgColor = header.getBackground(); } setForeground(fgColor); setFont(header.getFont()); isPaintingForPrint = header.isPaintingForPrint(); } if (!isPaintingForPrint && table.getRowSorter() != null) { if (!horizontalTextPositionSet) { // There is a row sorter, and the developer hasn't // set a text position, change to leading. setHorizontalTextPosition(JLabel.LEADING); } java.util.List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys(); if (sortKeys.size() > 0 && sortKeys.get(0).getColumn() == table.convertColumnIndexToModel(column)) { switch (sortKeys.get(0).getSortOrder()) { case ASCENDING: sortIcon = UIManager.getIcon("Table.ascendingSortIcon"); break; case DESCENDING: sortIcon = UIManager.getIcon("Table.descendingSortIcon"); break; case UNSORTED: sortIcon = UIManager.getIcon("Table.naturalSortIcon"); break; } } } } SupportTableModel model = (SupportTableModel) table.getModel(); ImageIcon icon = model.getColumnIcon((String) value); BufferedImage i = ImageUtils.createCompatibleBufferedImage(18, 18, BufferedImage.BITMASK); Graphics2D g2d = i.createGraphics(); // setIcon(sortIcon); if (icon != null) { icon.paintIcon(this, g2d, 0, 0); setText(""); if (sortIcon != null) { g2d.setColor(getBackground()); g2d.fillRect(18 - sortIcon.getIconWidth() - 2, 18 - sortIcon.getIconHeight() - 2, sortIcon.getIconWidth() + 2, sortIcon.getIconHeight() + 2); sortIcon.paintIcon(this, g2d, 18 - sortIcon.getIconWidth() - 1, 18 - sortIcon.getIconHeight() - 1); } setIcon(new ImageIcon(i)); } else { setIcon(sortIcon); setText(value == null ? "" : value.toString()); } Border border = null; if (hasFocus) { border = UIManager.getBorder("TableHeader.focusCellBorder"); } if (border == null) { border = UIManager.getBorder("TableHeader.cellBorder"); } setBorder(border); return this; }
Example 3
Source File: TroopTableHeaderRenderer.java From dsworkbench with Apache License 2.0 | 4 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Icon sortIcon = null; boolean isPaintingForPrint = false; if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { Color fgColor = null; Color bgColor = null; if (hasFocus) { fgColor = UIManager.getColor("TableHeader.focusCellForeground"); bgColor = UIManager.getColor("TableHeader.focusCellBackground"); } if (fgColor == null) { fgColor = header.getForeground(); } if (bgColor == null) { bgColor = header.getBackground(); } setForeground(fgColor); setFont(header.getFont()); isPaintingForPrint = header.isPaintingForPrint(); } if (!isPaintingForPrint && table.getRowSorter() != null) { if (!horizontalTextPositionSet) { // There is a row sorter, and the developer hasn't // set a text position, change to leading. setHorizontalTextPosition(JLabel.LEADING); } java.util.List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys(); if (sortKeys.size() > 0 && sortKeys.get(0).getColumn() == table.convertColumnIndexToModel(column)) { switch (sortKeys.get(0).getSortOrder()) { case ASCENDING: sortIcon = UIManager.getIcon("Table.ascendingSortIcon"); break; case DESCENDING: sortIcon = UIManager.getIcon("Table.descendingSortIcon"); break; case UNSORTED: sortIcon = UIManager.getIcon("Table.naturalSortIcon"); break; } } } } TroopsTableModel model = (TroopsTableModel) table.getModel(); ImageIcon icon = model.getColumnIcon((String) value); BufferedImage i = ImageUtils.createCompatibleBufferedImage(18, 18, BufferedImage.BITMASK); Graphics2D g2d = i.createGraphics(); // setIcon(sortIcon); if (icon != null) { icon.paintIcon(this, g2d, 0, 0); setText(""); if (sortIcon != null) { g2d.setColor(getBackground()); g2d.fillRect(18 - sortIcon.getIconWidth() - 2, 18 - sortIcon.getIconHeight() - 2, sortIcon.getIconWidth() + 2, sortIcon.getIconHeight() + 2); sortIcon.paintIcon(this, g2d, 18 - sortIcon.getIconWidth() - 1, 18 - sortIcon.getIconHeight() - 1); } setIcon(new ImageIcon(i)); } else { setIcon(sortIcon); setText(value == null ? "" : value.toString()); } Border border = null; if (hasFocus) { border = UIManager.getBorder("TableHeader.focusCellBorder"); } if (border == null) { border = UIManager.getBorder("TableHeader.cellBorder"); } setBorder(border); return this; }
Example 4
Source File: SeaGlassTableHeaderUI.java From seaglass with Apache License 2.0 | 4 votes |
/** * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, * java.lang.Object, boolean, boolean, int, int) */ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Icon sortIcon = null; boolean isPaintingForPrint = false; if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { Color fgColor = null; Color bgColor = null; if (hasFocus) { fgColor = DefaultLookup.getColor(this, ui, "TableHeader.focusCellForeground"); bgColor = DefaultLookup.getColor(this, ui, "TableHeader.focusCellBackground"); } if (fgColor == null) { fgColor = header.getForeground(); } if (bgColor == null) { bgColor = header.getBackground(); } setForeground(fgColor); setBackground(bgColor); setFont(header.getFont()); isPaintingForPrint = header.isPaintingForPrint(); } if (!isPaintingForPrint && table.getRowSorter() != null) { SortOrder sortOrder = getColumnSortOrder(table, column); if (sortOrder != null) { switch (sortOrder) { case ASCENDING: sortIcon = DefaultLookup.getIcon(this, ui, "Table.ascendingSortIcon"); break; case DESCENDING: sortIcon = DefaultLookup.getIcon(this, ui, "Table.descendingSortIcon"); break; case UNSORTED: sortIcon = DefaultLookup.getIcon(this, ui, "Table.naturalSortIcon"); break; } } } } if (value instanceof Icon) { setText(""); setIcon((Icon) value); } else if (value instanceof JLabel) { JLabel label = (JLabel) value; setText(label.getText()); setIcon(label.getIcon()); setHorizontalAlignment(label.getHorizontalAlignment()); setHorizontalTextPosition(label.getHorizontalTextPosition()); setVerticalAlignment(label.getVerticalAlignment()); setVerticalTextPosition(label.getVerticalTextPosition()); setToolTipText(label.getToolTipText()); } else { setText(value == null ? "" : value.toString()); setIcon(null); } sortArrow = sortIcon; Border border = null; if (hasFocus) { border = DefaultLookup.getBorder(this, ui, "TableHeader.focusCellBorder"); } if (border == null) { border = DefaultLookup.getBorder(this, ui, "TableHeader.cellBorder"); } setBorder(border); return this; }
Example 5
Source File: WebTableHeaderCellRenderer.java From weblaf with GNU General Public License v3.0 | 4 votes |
@Override public Component getTableCellRendererComponent ( final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column ) { // Whether we are printing the result or not boolean isPaintingForPrint = false; // Updating custom style identifier if ( table != null ) { setStyleId ( StyleId.tableHeaderCellRenderer.at ( table.getTableHeader () ) ); } // Title icon Icon sortIcon = null; if ( table != null ) { final JTableHeader header = table.getTableHeader (); if ( header != null ) { Color fgColor = null; Color bgColor = null; if ( hasFocus ) { fgColor = UIManager.getColor ( "TableHeader.focusCellForeground" ); bgColor = UIManager.getColor ( "TableHeader.focusCellBackground" ); } if ( fgColor == null ) { fgColor = header.getForeground (); } if ( bgColor == null ) { bgColor = header.getBackground (); } setForeground ( fgColor ); setBackground ( bgColor ); setFont ( header.getFont () ); isPaintingForPrint = header.isPaintingForPrint (); } if ( !isPaintingForPrint && table.getRowSorter () != null ) { if ( !horizontalTextPositionSet ) { // There is a row sorter, and the developer hasn't // set a text position, change to leading. setHorizontalTextPosition ( JLabel.LEADING ); } final List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter ().getSortKeys (); if ( sortKeys.size () > 0 && sortKeys.get ( 0 ).getColumn () == table.convertColumnIndexToModel ( column ) ) { switch ( sortKeys.get ( 0 ).getSortOrder () ) { case ASCENDING: sortIcon = UIManager.getIcon ( "Table.ascendingSortIcon" ); break; case DESCENDING: sortIcon = UIManager.getIcon ( "Table.descendingSortIcon" ); break; case UNSORTED: sortIcon = UIManager.getIcon ( "Table.naturalSortIcon" ); break; } } } } setIcon ( sortIcon ); // Title text setText ( value == null ? "" : value.toString () ); return this; }