List of usage examples for javax.swing JTable setColumnModel
@BeanProperty(description = "The object governing the way columns appear in the view.") public void setColumnModel(final TableColumnModel columnModel)
From source file:DefaultsDisplay.java
protected JTable createDefaultsTable() { JTable table = new JTable(new UIDefaultsTableModel()); table.setRowHeight(rowHeight);//from www . ja va 2 s .c o m table.setShowHorizontalLines(false); table.setShowVerticalLines(false); table.setIntercellSpacing(new Dimension(0, 0)); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); initFilters(table); DefaultTableColumnModel columnModel = new DefaultTableColumnModel(); Color rowColors[] = new Color[2]; rowColors[0] = UIManager.getColor("Table.background"); rowColors[1] = new Color((int) (rowColors[0].getRed() * .90), (int) (rowColors[0].getGreen() * .95), (int) (rowColors[0].getBlue() * .95)); int width = 0; TableColumn column = new TableColumn(); column.setCellRenderer(new KeyRenderer(rowColors)); column.setModelIndex(UIDefaultsTableModel.KEY_COLUMN); column.setHeaderValue("Key"); column.setPreferredWidth(250); columnModel.addColumn(column); width += column.getPreferredWidth(); column = new TableColumn(); column.setCellRenderer(new RowRenderer(rowColors)); column.setModelIndex(UIDefaultsTableModel.TYPE_COLUMN); column.setHeaderValue("Type"); column.setPreferredWidth(250); columnModel.addColumn(column); width += column.getPreferredWidth(); column = new TableColumn(); column.setCellRenderer(new ValueRenderer(rowColors)); column.setModelIndex(UIDefaultsTableModel.VALUE_COLUMN); column.setHeaderValue("Value"); column.setPreferredWidth(300); columnModel.addColumn(column); width += column.getPreferredWidth(); table.setColumnModel(columnModel); table.setPreferredScrollableViewportSize(new Dimension(width, 12 * rowHeight)); return table; }
From source file:vista.promocion.DiagPromocion.java
private void configurarTabla(JTable tbl) { JViewport scroll = (JViewport) tbl.getParent(); int ancho = scroll.getWidth(); int anchoColumna = 0; TableColumnModel modeloColumna = tbl.getColumnModel(); TableColumn columnaTabla;/*from w ww .j a v a 2s . c o m*/ for (int i = 0; i < tbl.getColumnCount(); i++) { columnaTabla = modeloColumna.getColumn(i); switch (i) { case 0: anchoColumna = (1 * ancho) / 100; break; case 1: anchoColumna = (20 * ancho) / 100; break; case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: anchoColumna = (5 * ancho) / 100; break; } columnaTabla.setPreferredWidth(anchoColumna); tbl.setColumnModel(modeloColumna); } tbl.getTableHeader().setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10)); tbl.getTableHeader().setBackground(java.awt.Color.WHITE); tbl.getTableHeader().setForeground(Color.BLACK); //Si le queremos cambiar el tamao a la tablita tbl.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10)); }
From source file:vista.ventas.DiagOrdenesDeCompra.java
private void configurarTabla(JTable tbl) { JViewport scroll = (JViewport) tbl.getParent(); int ancho = scroll.getWidth(); int anchoColumna = 0; TableColumnModel modeloColumna = tbl.getColumnModel(); TableColumn columnaTabla;/*from w w w . j av a2 s . c o m*/ for (int i = 0; i < tbl.getColumnCount(); i++) { columnaTabla = modeloColumna.getColumn(i); switch (i) { case 0: anchoColumna = (1 * ancho) / 100; break; case 1: anchoColumna = (20 * ancho) / 100; break; case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: anchoColumna = (5 * ancho) / 100; break; } columnaTabla.setPreferredWidth(anchoColumna); tbl.setColumnModel(modeloColumna); } tbl.getTableHeader().setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10)); tbl.getTableHeader().setBackground(java.awt.Color.WHITE); tbl.getTableHeader().setForeground(Color.BLACK); tbl.getTableHeader().setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 18)); //Si le queremos cambiar el tamao a la tablita tbl.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 18)); }
From source file:vista.ventas.DialogEntregas.java
private void configurarTabla(JTable tbl) { JViewport scroll = (JViewport) tbl.getParent(); int ancho = scroll.getWidth(); int anchoColumna = 0; TableColumnModel modeloColumna = tbl.getColumnModel(); TableColumn columnaTabla;//ww w . j ava 2 s.c om for (int i = 0; i < tbl.getColumnCount(); i++) { columnaTabla = modeloColumna.getColumn(i); switch (i) { case 0: anchoColumna = 1 / 100; break; case 1: anchoColumna = (20 * ancho) / 100; break; case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: anchoColumna = (5 * ancho) / 100; break; } columnaTabla.setPreferredWidth(anchoColumna); tbl.setColumnModel(modeloColumna); } tbl.getTableHeader().setBackground(java.awt.Color.WHITE); tbl.getTableHeader().setForeground(Color.BLACK); tbl.getTableHeader().setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 14)); //Si le queremos cambiar el tamao a la tablita tbl.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 14)); }