List of usage examples for javax.swing.table TableColumn setHeaderValue
@BeanProperty(description = "The text to be used by the header renderer.") public void setHeaderValue(Object headerValue)
Object
whose string representation will be used as the value for the headerRenderer
. From source file:com.hp.alm.ali.idea.ui.MultipleItemsDialog.java
private TableColumn createColumn(int index, TableModel model, int preferredWidth, Integer minWidth) { TableColumn column = new TableColumn(index); column.setPreferredWidth(preferredWidth); if (minWidth != null) { column.setMinWidth(minWidth);/* w w w . j a v a2 s. co m*/ } column.setHeaderValue(model.getColumnName(index)); return column; }
From source file:DefaultsDisplay.java
protected JTable createDefaultsTable() { JTable table = new JTable(new UIDefaultsTableModel()); table.setRowHeight(rowHeight);/*from ww w . ja v a 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:statisticsintegration.StatisticsLabr.java
private void ok2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ok2ActionPerformed Integer size = 0;//from w w w . j a va 2 s . c om System.out.println("Nisulod"); try { size = Integer.parseInt(Size.getText()); } catch (Exception e) { Warnings.setText("Invalid size"); } Warnings1.setText(""); if (Categorical.isSelected() == true && Numerical.isSelected() == false) { String header[] = { "Values", "Percentage" }; DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); dtm.setRowCount(size); dtm.setColumnCount(2); for (int i = 0; i < jTable1.getColumnCount(); i++) { TableColumn column1 = jTable1.getTableHeader().getColumnModel().getColumn(i); column1.setHeaderValue(header[i]); } } //GEN-LAST:event_ok2ActionPerformed else if (Numerical.isSelected() == true && Categorical.isSelected() == false) { String header[] = { "VAL", "CL", "True CL", "MP", "FQ", "%", "CF", "C%" }; DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); dtm.setRowCount(size); dtm.setColumnCount(8); for (int i = 0; i < jTable1.getColumnCount(); i++) { TableColumn column1 = jTable1.getTableHeader().getColumnModel().getColumn(i); column1.setHeaderValue(header[i]); } } else { Warnings1.setText("Select one operation"); } }
From source file:NewApplication.java
private void EditTable(Class clazz) { // TODO add your handling code here: DefaultTableModel model = (DefaultTableModel) jTable2.getModel(); model.setColumnCount(3);//w w w . j a v a2 s .co m model.setNumRows(0); jTable2.setModel(model); TableColumn tc = jTable2.getColumnModel().getColumn(0); tc.setHeaderValue("Field Name"); tc = jTable2.getColumnModel().getColumn(1); tc.setHeaderValue("Value"); tc = jTable2.getColumnModel().getColumn(2); tc.setHeaderValue("Type"); try { Field[] fields = clazz.getDeclaredFields(); for (Field f : fields) { Object[] obs = new Object[3]; model = (DefaultTableModel) jTable2.getModel(); f.setAccessible(true); obs[0] = f.getName(); obs[2] = f.getType().getName(); if (f.getName() == "" || f.getName() == null) continue; model.addRow(obs); jTable2.setModel(model); } jTable2.repaint(); } catch (Exception ex) { } ; }
From source file:NewApplication.java
private void EditTable(Class clazz, Object object) { // TODO add your handling code here: DefaultTableModel model = (DefaultTableModel) jTable2.getModel(); model.setColumnCount(3);// www.ja v a 2 s. c o m model.setNumRows(0); jTable2.setModel(model); TableColumn tc = jTable2.getColumnModel().getColumn(0); tc.setHeaderValue("Field Name"); tc = jTable2.getColumnModel().getColumn(1); tc.setHeaderValue("Value"); tc = jTable2.getColumnModel().getColumn(2); tc.setHeaderValue("Type"); try { Field[] fields = clazz.getDeclaredFields(); for (Field f : fields) { Object[] obs = new Object[3]; model = (DefaultTableModel) jTable2.getModel(); f.setAccessible(true); obs[0] = f.getName(); obs[1] = f.get(object); obs[2] = f.getType().getName(); if (f.getName() == "" || f.getName() == null) continue; model.addRow(obs); jTable2.setModel(model); } jTable2.repaint(); } catch (Exception ex) { } ; }
From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java
public DirectoryBrowser(UserPreferences preferences, File directory) { Validate.notNull(preferences, "The given user preferences are null"); Validate.notNull(directory, "The given directory is null"); Validate.isTrue(directory.exists(),/* ww w . jav a2 s. c o m*/ String.format("The given directory '%s' doesn't exist", directory.getAbsolutePath())); Validate.isTrue(directory.isDirectory(), String.format("The given path '%s' doesn't denote a directory", directory.getAbsolutePath())); this.preferences = preferences; // Layout, columns & rows setLayout(new MigLayout("insets 0px", "[grow]", "[]1[grow]1[]")); this.tableModel = new FileTableModel(this); this.table = new JTable(tableModel); this.table.setBackground(Utils.getDefaultBackgroundColor()); this.table.addKeyListener(this); this.table.addMouseListener(this); this.table.addFocusListener(this); this.table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); this.table.getSelectionModel().addListSelectionListener(this); // Listen to column event resize events final ColumnEventHelper eventHelper = new ColumnEventHelper(this); this.table.getColumnModel().addColumnModelListener(eventHelper); this.table.getTableHeader().addMouseListener(eventHelper); // Render the table headers with a bold font this.table.getTableHeader().setFont(Utils.getBoldFont(this.table.getTableHeader().getFont())); this.table.getTableHeader().setBackground(Utils.getDefaultBackgroundColor()); this.table.getTableHeader().setDefaultRenderer(new TableHeaderRenderer()); this.table.getTableHeader().addMouseListener(this); final TableColumn typeColumn = this.table.getColumn(FileTableModel.COLUMN_TYPE); typeColumn.setCellRenderer(new FileTypeRenderer()); typeColumn.setResizable(false); typeColumn.setHeaderValue(""); typeColumn.setMaxWidth(Icons.FOLDER_ICON.getIconWidth() + 5); final TableColumn fileColumn = this.table.getColumn(FileTableModel.COLUMN_NAME); fileColumn.setCellRenderer(new FileNameRenderer()); fileColumn.setResizable(true); final TableColumn sizeColumn = this.table.getColumn(FileTableModel.COLUMN_SIZE); sizeColumn.setCellRenderer(new FileSizeRenderer()); sizeColumn.setResizable(true); // Dynamically set the column to the correct size final TableColumn lastUpdateColumn = this.table.getColumn(FileTableModel.COLUMN_LAST_UPDATE); lastUpdateColumn.setCellRenderer(new LastUpdateRenderer()); lastUpdateColumn.setResizable(false); lastUpdateColumn.setMaxWidth(Utils.getTimestampRenderWidth() + 5); lastUpdateColumn.setMinWidth(Utils.getTimestampRenderWidth() + 5); // Use a square border (not one with rounded corners) this.directoryButton.setBorder(Utils.createRaisedBevelBorder()); this.directoryButton.setFont(Utils.getDefaultFont()); this.directoryButton.setFocusable(false); this.directoryButton.setHorizontalAlignment(SwingConstants.LEFT); this.summary = new JLabel(" "); this.summary.setBorder(Utils.createRaisedBevelBorder()); add(directoryButton, "grow, wrap"); add(new JScrollPane(table), "grow, wrap"); add(summary, "grow"); // Set the directory (this will populate the table) setDirectory(directory); }
From source file:NewApplication.java
private void EditTable() { // TODO add your handling code here: DefaultTableModel model = (DefaultTableModel) jTable2.getModel(); model.setColumnCount(3);/*from w w w.j a v a 2s.co m*/ model.setNumRows(0); jTable2.setModel(model); TableColumn tc = jTable2.getColumnModel().getColumn(0); tc.setHeaderValue("Field Name"); tc = jTable2.getColumnModel().getColumn(1); tc.setHeaderValue("Value"); tc = jTable2.getColumnModel().getColumn(2); tc.setHeaderValue("Type"); int index = listEntities.getSelectedIndex(); if (index < 0) return; Class clazz = null; if (ens != null) clazz = (Class) ens.get(index); try { Field[] fields = clazz.getDeclaredFields(); for (Field f : fields) { Object[] obs = new Object[3]; model = (DefaultTableModel) jTable2.getModel(); f.setAccessible(true); obs[0] = f.getName(); obs[2] = f.getType().getName(); if (f.getName() == "" || f.getName() == null) continue; model.addRow(obs); jTable2.setModel(model); } jTable2.repaint(); } catch (Exception ex) { } ; }
From source file:NewApplication.java
public void LoadTable(Class clazz) { model = new DefaultTableModel(); Field[] fields = clazz.getDeclaredFields(); Integer C = fields.length;/*from w w w . ja v a2s. com*/ model.setColumnCount(C); jTable1.setModel(model); for (int i = 0; i < C; i++) { TableColumn tc = jTable1.getColumnModel().getColumn(i); Field field = fields[i]; tc.setHeaderValue(field.getName()); } // Replace model jTable1.repaint(); }
From source file:org.jdal.swing.ListTableModel.java
/** * Create a TableColumnModel for JTable. * Try to use sizes and cell renderers from property descriptors. * @return a new TableColumnModel based on PropertyDescriptors *///from w w w . j ava 2 s . c om public TableColumnModel getTableColumnModel() { TableColumnModel tcm = new DefaultTableColumnModel(); int baseIndex = 0; if (usingChecks) { TableColumn tableColumn = new TableColumn(0); tableColumn.setMaxWidth(50); tcm.addColumn(tableColumn); baseIndex++; } for (int i = 0; i < columnNames.size(); i++) { String name = this.columnNames.get(i); TableColumn tableColumn = new TableColumn(baseIndex + i); tableColumn.setHeaderValue(displayNames.get(i)); if (pds != null && pds.size() > 0) { PropertyDescriptor descriptor = pds.get(i); // property values for TableColumns if (descriptor != null) { Integer maxWidth = getColumnWidth(name); if (maxWidth != null) tableColumn.setMaxWidth(maxWidth.intValue()); tableColumn.setCellRenderer(getColumnRenderer(name)); tableColumn.setCellEditor(getColumnEditor(name)); } } tcm.addColumn(tableColumn); } if (usingActions) { baseIndex += columnNames.size(); for (int i = 0; i < actions.size(); i++) { TableColumn tableColumn = new TableColumn(baseIndex + i); tableColumn.setCellRenderer(new ActionCellRenderer()); tableColumn.setMaxWidth(50); // tableColumn.setCellEditor(new ActionCellEditor()) tcm.addColumn(tableColumn); } } return tcm; }
From source file:com.vgi.mafscaling.ClosedLoop.java
private JTable createAfrDataTable(JPanel panel, String tableName, int gridy) { final JTable afrTable = new JTable() { private static final long serialVersionUID = 6526901361175099297L; public boolean isCellEditable(int row, int column) { return false; };//ww w . j a v a 2 s . c o m }; DefaultTableColumnModel afrModel = new DefaultTableColumnModel(); final TableColumn afrColumn = new TableColumn(0, 250); afrColumn.setHeaderValue(tableName); afrModel.addColumn(afrColumn); JTableHeader lblAfrTableName = afrTable.getTableHeader(); lblAfrTableName.setColumnModel(afrModel); lblAfrTableName.setReorderingAllowed(false); DefaultTableCellRenderer headerRenderer = (DefaultTableCellRenderer) lblAfrTableName.getDefaultRenderer(); headerRenderer.setHorizontalAlignment(SwingConstants.LEFT); GridBagConstraints gbc_lblAfrTableName = new GridBagConstraints(); gbc_lblAfrTableName.insets = new Insets((gridy == 0 ? 0 : 5), 0, 0, 0); gbc_lblAfrTableName.anchor = GridBagConstraints.PAGE_START; gbc_lblAfrTableName.fill = GridBagConstraints.HORIZONTAL; gbc_lblAfrTableName.gridx = 0; gbc_lblAfrTableName.gridy = gridy; panel.add(lblAfrTableName, gbc_lblAfrTableName); afrTable.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { afrColumn.setWidth(afrTable.getWidth()); } }); afrTable.getTableHeader().setReorderingAllowed(false); afrTable.setColumnSelectionAllowed(true); afrTable.setCellSelectionEnabled(true); afrTable.setBorder(new LineBorder(new Color(0, 0, 0))); afrTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); afrTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); afrTable.setModel(new DefaultTableModel(AfrTableRowCount, AfrTableColumnCount)); Utils.initializeTable(afrTable, ColumnWidth); if (tableName.equals(Afr1TableName)) { Format[][] formatMatrix = { { new DecimalFormat("#"), new DecimalFormat("0.00") } }; NumberFormatRenderer renderer = (NumberFormatRenderer) afrTable.getDefaultRenderer(Object.class); renderer.setFormats(formatMatrix); } else if (tableName.equals(Afr2TableName)) { Format[][] formatMatrix = { { new DecimalFormat("#"), new DecimalFormat("0.00") }, { new DecimalFormat("#"), new DecimalFormat("#") } }; NumberFormatRenderer renderer = (NumberFormatRenderer) afrTable.getDefaultRenderer(Object.class); renderer.setFormats(formatMatrix); } GridBagConstraints gbc_afrTable = new GridBagConstraints(); gbc_afrTable.insets = new Insets(0, 0, 0, 0); gbc_afrTable.anchor = GridBagConstraints.PAGE_START; gbc_afrTable.gridx = 0; gbc_afrTable.gridy = gridy + 1; panel.add(afrTable, gbc_afrTable); excelAdapter.addTable(afrTable, true, false); return afrTable; }