List of usage examples for javax.swing JTable getGraphics
@BeanProperty(bound = false)
public Graphics getGraphics()
From source file:com.limegroup.gnutella.gui.GUIUtils.java
/** * It will adjust the column width to match the widest element. * (You might not want to use this for every column, consider some columns might be really long) * @param model// ww w .ja v a 2 s . c o m * @param columnIndex * @param table * @return */ public static void adjustColumnWidth(TableModel model, int columnIndex, int maxWidth, int rightPadding, JTable table) { if (columnIndex > model.getColumnCount() - 1) { //invalid column index return; } if (!model.getColumnClass(columnIndex).equals(String.class)) { return; } String longestValue = ""; for (int row = 0; row < model.getRowCount(); row++) { String strValue = (String) model.getValueAt(row, columnIndex); if (strValue != null && strValue.length() > longestValue.length()) { longestValue = strValue; } } Graphics g = table.getGraphics(); try { int suggestedWidth = (int) g.getFontMetrics(table.getFont()).getStringBounds(longestValue, g) .getWidth(); table.getColumnModel().getColumn(columnIndex) .setPreferredWidth(((suggestedWidth > maxWidth) ? maxWidth : suggestedWidth) + rightPadding); } catch (Exception e) { table.getColumnModel().getColumn(columnIndex).setPreferredWidth(maxWidth); e.printStackTrace(); } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java
protected void applyFont(JTable table, Font font) { Graphics graphics = table.getGraphics(); if (graphics != null) { FontMetrics metrics = graphics.getFontMetrics(font); defaultRowHeight = metrics.getHeight() + DEFAULT_ROW_MARGIN; fontInitialized = true;/*from w w w . ja v a2s.co m*/ if (impl != null) { packRows(); } } }
From source file:jp.massbank.spectrumsearch.SearchPage.java
/** * ??/*w ww . ja v a 2 s. c o m*/ */ private void updateSelectQueryTable(JTable tbl) { // ? this.setCursor(waitCursor); int selRow = tbl.getSelectedRow(); if (selRow >= 0) { tbl.clearSelection(); Color defColor = tbl.getSelectionBackground(); tbl.setRowSelectionInterval(selRow, selRow); tbl.setSelectionBackground(Color.PINK); tbl.update(tbl.getGraphics()); tbl.setSelectionBackground(defColor); } // ? this.setCursor(Cursor.getDefaultCursor()); }