List of usage examples for javax.swing.table TableColumn setCellRenderer
@BeanProperty(description = "The renderer to use for cell values.") public void setCellRenderer(TableCellRenderer cellRenderer)
TableCellRenderer
used by JTable
to draw individual values for this column. From source file:org.openconcerto.task.TodoListPanel.java
private void initTable(int mode) { this.t.setBlockRepaint(true); this.t.setBlockEventOnColumn(true); this.model.setMode(mode); this.t.getColumnModel().getColumn(0).setCellRenderer(this.a); this.t.getColumnModel().getColumn(0).setCellEditor(this.a); this.t.setBlockEventOnColumn(true); setIconForColumn(0, this.iconTache); setIconForColumn(1, this.iconPriorite); this.t.setBlockEventOnColumn(true); this.t.getColumnModel().getColumn(1).setCellEditor(this.iconEditor); final JTextField textField = new JTextField() { @Override// w w w. ja v a2s .c o m public void paint(Graphics g) { super.paint(g); g.setColor(TodoListPanel.this.t.getGridColor()); g.fillRect(getWidth() - 19, 0, 1, getHeight()); g.setColor(new Color(250, 250, 250)); g.fillRect(getWidth() - 18, 0, 18, getHeight()); g.setColor(Color.BLACK); for (int i = 0; i < 3; i++) { int x = getWidth() - 14 + i * 4; int y = getHeight() - 5; g.fillRect(x, y, 1, 2); } } }; textField.setBorder(BorderFactory.createEmptyBorder()); final DefaultCellEditor defaultCellEditor = new DefaultCellEditor(textField); textField.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { if (e.getX() > textField.getWidth() - 19) { TodoListElement l = getTaskAt( SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), TodoListPanel.this.t)); TodoListPanel.this.t.editingCanceled(new ChangeEvent(this)); JFrame f = new JFrame(TM.tr("details")); f.setContentPane(new TodoListElementEditorPanel(l)); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setSize(500, 200); f.setLocation(50, e.getYOnScreen() + TodoListPanel.this.t.getRowHeight()); f.setVisible(true); } } }); this.t.getColumnModel().getColumn(2).setCellEditor(defaultCellEditor); this.t.getColumnModel().getColumn(3).setMaxWidth(300); this.t.getColumnModel().getColumn(3).setMinWidth(100); this.timestampTableCellEditorCreated.stopCellEditing(); this.timestampTableCellEditorDone.stopCellEditing(); this.timestampTableCellEditorDeadLine.stopCellEditing(); if (this.model.getMode() == TodoListModel.EXTENDED_MODE) { this.t.getColumnModel().getColumn(3).setCellRenderer(this.timestampTableCellRendererCreated); this.t.getColumnModel().getColumn(3).setCellEditor(this.timestampTableCellEditorCreated); this.t.getColumnModel().getColumn(4).setCellRenderer(this.timestampTableCellRendererDone); this.t.getColumnModel().getColumn(4).setCellEditor(this.timestampTableCellEditorDone); this.t.getColumnModel().getColumn(5).setCellRenderer(this.timestampTableCellRendererDeadLine); this.t.getColumnModel().getColumn(5).setCellEditor(this.timestampTableCellEditorDeadLine); } else { this.t.getColumnModel().getColumn(3).setCellRenderer(this.timestampTableCellRendererDeadLine); this.t.getColumnModel().getColumn(3).setCellEditor(this.timestampTableCellEditorDeadLine); } final TableColumn userColumn = this.t.getColumnModel() .getColumn(this.t.getColumnModel().getColumnCount() - 1); userColumn.setCellRenderer(this.userTableCellRenderer); userColumn.setMaxWidth(150); userColumn.setMinWidth(100); t.setEnabled(false); initUserCellEditor(userColumn); this.t.setBlockEventOnColumn(false); this.t.setBlockRepaint(false); this.t.getColumnModel().getColumn(1).setCellRenderer(this.iconRenderer); // Better look this.t.setShowHorizontalLines(false); this.t.setGridColor(new Color(230, 230, 230)); this.t.setRowHeight(new JTextField(" ").getPreferredSize().height + 4); AlternateTableCellRenderer.UTILS.setAllColumns(this.t); this.t.repaint(); }
From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.FileSelectionTable.java
/** * Helper method to setup the column as a boolean column * @param column the column to set//w w w .j a v a 2 s. c o m */ private void setColumnAsBoolean(TableColumn column) { column.setCellEditor(table.getDefaultEditor(Boolean.class)); column.setCellRenderer(table.getDefaultRenderer(Boolean.class)); column.setResizable(false); }
From source file:org.openstreetmap.josm.gui.preferences.imagery.CacheContentsPanel.java
private static JTable getTableForCache(final CacheAccess<String, BufferedImageCacheEntry> cache, final TableModel tableModel) { final JTable ret = new JTable(tableModel); ButtonColumn buttonColumn = new ButtonColumn(new AbstractAction() { @Override/*www .ja v a2 s .co m*/ public void actionPerformed(ActionEvent e) { int row = ret.convertRowIndexToModel(ret.getEditingRow()); tableModel.setValueAt("0", row, 1); cache.remove(ret.getValueAt(row, 0).toString() + ':'); } }); TableColumn tableColumn = ret.getColumnModel().getColumn(2); tableColumn.setCellRenderer(buttonColumn); tableColumn.setCellEditor(buttonColumn); return ret; }
From source file:org.pentaho.reporting.ui.datasources.table.TableEditor.java
/** * Creates default columns for the table from the data model using the <code>getColumnCount</code> method defined in * the <code>TableModel</code> interface. * <p/>/*from w w w . j av a2 s.co m*/ * Clears any existing columns before creating the new columns based on information from the model. * * @see #getAutoCreateColumnsFromModel */ public void createDefaultColumnsFromModel() { final TableModel m = getModel(); if (m != null) { // Remove any current columns final TableColumnModel cm = getColumnModel(); while (cm.getColumnCount() > 0) { cm.removeColumn(cm.getColumn(0)); } // Create new columns from the data model info for (int i = 0; i < m.getColumnCount(); i++) { if (i == 0) { final TableColumn column = new TableColumn(i); column.setCellRenderer(tableHeader.getDefaultRenderer()); addColumn(column); continue; } final EditableHeaderTableColumn newColumn = new EditableHeaderTableColumn(i); newColumn.setHeaderEditor(new TypedHeaderCellEditor()); addColumn(newColumn); } } }
From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java
private void updateColumnModel() { TableColumnModel columnModel = table.getColumnModel(); totalFlex = 0;/*from w w w. j a v a 2s. com*/ for (int i = 0; i < columns.getChildNodes().size(); i++) { if (i >= columnModel.getColumnCount()) { break; } SwingTreeCol child = (SwingTreeCol) columns.getChildNodes().get(i); TableColumn col = columnModel.getColumn(i); totalFlex += child.getFlex(); col.setHeaderValue(child.getLabel()); col.setCellEditor(getCellEditor(child)); col.setCellRenderer(getCellRenderer(child)); // List<XulComponent> cells = child.getChildNodes(); // for(int z=0; z<cells.size(); z++){ // XulComponent cell = cells.get(z); // } } }
From source file:org.piraso.ui.api.StackTraceFilterDialog.java
private void initTable() { TableColumn regexColumn = jtable.getColumnModel().getColumn(0); TableColumn boldColumn = jtable.getColumnModel().getColumn(1); regexColumn.setHeaderValue("Regex"); regexColumn.setPreferredWidth(210);//w w w.ja v a2 s . com boldColumn.setHeaderValue("Bold"); boldColumn.setPreferredWidth(30); boldColumn.setMaxWidth(30); boldColumn.setCellEditor(jtable.getDefaultEditor(Boolean.class)); boldColumn.setCellRenderer(jtable.getDefaultRenderer(Boolean.class)); jtable.setShowHorizontalLines(false); jtable.setAutoscrolls(true); jtable.setColumnSelectionAllowed(false); jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jtable.getTableHeader().setReorderingAllowed(false); }
From source file:org.piraso.ui.base.ContextMonitorTopComponent.java
private void initColumns() { TableColumn numColumn = table.getColumnModel().getColumn(0); TableColumn messageColumn;/*from w ww. j a va2s . c o m*/ TableColumn elapseColumn; numColumn.setHeaderValue(""); numColumn.setMaxWidth(43); numColumn.setCellRenderer(CELL_RENDERER); showType = SingleModelManagers.GENERAL_SETTINGS.get().isShowType(); if (showType) { TableColumn typeColumn = table.getColumnModel().getColumn(1); messageColumn = table.getColumnModel().getColumn(2); typeColumn.setHeaderValue("Type"); typeColumn.setMaxWidth(125); typeColumn.setCellRenderer(CELL_RENDERER); } else { messageColumn = table.getColumnModel().getColumn(1); } showElapseTime = SingleModelManagers.GENERAL_SETTINGS.get().isShowElapseTime(); if (showElapseTime) { if (showType) { elapseColumn = table.getColumnModel().getColumn(3); } else { elapseColumn = table.getColumnModel().getColumn(2); } elapseColumn.setHeaderValue("Elapse"); elapseColumn.setMaxWidth(100); elapseColumn.setCellRenderer(CELL_RENDERER); } messageColumn.setHeaderValue("Message"); messageColumn.setPreferredWidth(700); messageColumn.setCellRenderer(CELL_RENDERER); }
From source file:org.piraso.ui.base.ExportDialog.java
private void initTable() { TableColumn selectionColumn = jtable.getColumnModel().getColumn(0); TableColumn boldOption = jtable.getColumnModel().getColumn(1); selectionColumn.setHeaderValue(""); selectionColumn.setPreferredWidth(30); selectionColumn.setMaxWidth(30);//from www . java 2 s . com selectionColumn.setCellEditor(jtable.getDefaultEditor(Boolean.class)); selectionColumn.setCellRenderer(jtable.getDefaultRenderer(Boolean.class)); boldOption.setHeaderValue("Option"); boldOption.setPreferredWidth(200); jtable.setShowHorizontalLines(false); jtable.setAutoscrolls(true); jtable.setColumnSelectionAllowed(false); jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jtable.getTableHeader().setReorderingAllowed(false); }
From source file:org.piraso.ui.base.SaveMonitorInstanceDialog.java
private void initTable() { TableColumn selectionColumn = jtable.getColumnModel().getColumn(0); TableColumn boldOption = jtable.getColumnModel().getColumn(1); selectionColumn.setHeaderValue(""); selectionColumn.setPreferredWidth(30); selectionColumn.setMaxWidth(30);//from ww w . j av a 2s . co m selectionColumn.setCellEditor(jtable.getDefaultEditor(Boolean.class)); selectionColumn.setCellRenderer(jtable.getDefaultRenderer(Boolean.class)); boldOption.setHeaderValue("Request URL"); boldOption.setPreferredWidth(200); jtable.setShowHorizontalLines(false); jtable.setAutoscrolls(true); jtable.setColumnSelectionAllowed(false); jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jtable.getTableHeader().setReorderingAllowed(false); }
From source file:org.piraso.ui.sql.SQLViewTopComponent.java
private void initTable() { TableColumn numColumn = table.getColumnModel().getColumn(0); TableColumn methodColumn = table.getColumnModel().getColumn(1); TableColumn typeColumn = table.getColumnModel().getColumn(2); TableColumn valueColumn = table.getColumnModel().getColumn(3); numColumn.setHeaderValue(""); numColumn.setMaxWidth(30);/*from w ww .j a v a2s.c o m*/ numColumn.setCellRenderer(new AlignableTableCellRendererImpl(SwingConstants.RIGHT, false, true)); methodColumn.setHeaderValue("Method"); methodColumn.setPreferredWidth(300); typeColumn.setHeaderValue("Type"); typeColumn.setPreferredWidth(200); valueColumn.setHeaderValue("Value"); valueColumn.setPreferredWidth(200); }