1 19 20 24 25 package org.netbeans.modules.db.sql.visualeditor.querybuilder; 26 27 import javax.swing.JTable ; 28 29 import javax.swing.table.TableColumn ; 30 31 import java.awt.*; 32 33 import org.openide.ErrorManager; 34 35 import org.netbeans.modules.db.sql.visualeditor.Log; 36 37 40 public class QueryBuilderTable extends JTable { 41 42 private boolean DEBUG = false; 43 44 45 47 public QueryBuilderTable( QueryBuilderTableModel model) { 48 49 super(); 50 super.setModel( model ); 51 52 Log.err.log(ErrorManager.INFORMATIONAL, "Entering QueryBuilderTable ctor, model: " + model); 54 this.setAutoResizeMode (JTable.AUTO_RESIZE_OFF); 55 56 this.initColumnSizes(this, model); 58 this.setShowHorizontalLines(false); 59 this.setShowVerticalLines(false); 60 this.setBackground(Color.white); 61 this.setRowHeight(this.getRowHeight() + 2); 62 this.setRowSelectionAllowed (false); 63 this.setTableHeader (null); 64 } 65 66 67 69 private void initColumnSizes(JTable table, QueryBuilderTableModel model) { 70 71 TableColumn column = null; 72 Component comp = null; 73 int headerWidth = 0; 74 int cellWidth = 0; 75 76 for (int i = 0; i < getColumnCount(); i++) { 77 78 column = table.getColumnModel().getColumn(i); 79 80 comp = table.getDefaultRenderer(column.getClass()). 81 getTableCellRendererComponent( 82 table, column.getHeaderValue(), 83 false, false, -1, 0); 84 headerWidth = comp.getPreferredSize().width; 85 86 try { 87 comp = column.getHeaderRenderer(). 88 getTableCellRendererComponent( 89 null, column.getHeaderValue(), 90 false, false, 0, 0); 91 headerWidth = comp.getPreferredSize().width; 92 } catch (NullPointerException e) { 93 } 94 95 if ( i != 0 ) 96 { 97 for (int j=0; j< table.getRowCount(); j++) 98 { 99 comp = table.getDefaultRenderer(model.getColumnClass(i)). 100 getTableCellRendererComponent( 101 table, getValueAt(j, 2), 102 false, false, 0, i); 103 int tmpCellWidth = comp.getPreferredSize().width; 104 105 if ( tmpCellWidth > cellWidth ) 106 cellWidth = tmpCellWidth; 107 } 108 } 109 110 column.setPreferredWidth(Math.max(headerWidth+15, cellWidth+15)); 112 } 113 114 table.addNotify(); 115 } 116 } 117 | Popular Tags |