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.revager.gui.findings_list.FindingsListFrame.java
private void createAttPanel() { GridLayout grid = new GridLayout(4, 1); grid.setVgap(8);// ww w .j a v a 2s .com JPanel attendeeButtons = new JPanel(grid); addResiAtt = GUITools.newImageButton(); addResiAtt.setIcon(Data.getInstance().getIcon("addResiAtt_25x25_0.png")); addResiAtt.setRolloverIcon(Data.getInstance().getIcon("addResiAtt_25x25.png")); addResiAtt.setToolTipText(translate("Add Attendee from the Attendee Pool")); addResiAtt.addActionListener(ActionRegistry.getInstance().get(AddResiAttToProtAction.class.getName())); attendeeButtons.add(addResiAtt); JButton addAttendee = GUITools.newImageButton(); addAttendee.setIcon(Data.getInstance().getIcon("addAttendee_25x25_0.png")); addAttendee.setRolloverIcon(Data.getInstance().getIcon("addAttendee_25x25.png")); addAttendee.setToolTipText(translate("Add Attendee")); addAttendee.addActionListener(ActionRegistry.getInstance().get(AddAttToProtAction.class.getName())); attendeeButtons.add(addAttendee); removeAttendee = GUITools.newImageButton(); removeAttendee.setIcon(Data.getInstance().getIcon("removeAttendee_25x25_0.png")); removeAttendee.setRolloverIcon(Data.getInstance().getIcon("removeAttendee_25x25.png")); removeAttendee.setToolTipText(translate("Remove Attendee")); removeAttendee.addActionListener(ActionRegistry.getInstance().get(RemAttFromProtAction.class.getName())); attendeeButtons.add(removeAttendee); editAttendee = GUITools.newImageButton(); editAttendee.setIcon(Data.getInstance().getIcon("editAttendee_25x25_0.png")); editAttendee.setRolloverIcon(Data.getInstance().getIcon("editAttendee_25x25.png")); editAttendee.setToolTipText(translate("Edit Attendee")); editAttendee.addActionListener(ActionRegistry.getInstance().get(EditAttFromProtAction.class.getName())); attendeeButtons.add(editAttendee); editAttendee.setEnabled(false); removeAttendee.setEnabled(false); presentAttTable.setRowHeight(55); presentAttTable.getColumnModel().getColumn(0).setMaxWidth(55); presentAttTable.setShowHorizontalLines(false); presentAttTable.setShowVerticalLines(true); presentAttTable.setShowGrid(true); presentAttTable.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { ActionRegistry.getInstance().get(EditAttFromProtAction.class.getName()).actionPerformed(null); } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); TableCellRenderer renderer = (table, value, isSelected, hasFocus, row, column) -> { JLabel label = new JLabel((String) value); label.setOpaque(true); label.setBorder(new EmptyBorder(5, 5, 5, 5)); label.setFont(UI.VERY_LARGE_FONT); if (isSelected) { label.setBackground(presentAttTable.getSelectionBackground()); } else { if (row % 2 == 0) { label.setBackground(UI.TABLE_ALT_COLOR); } else { label.setBackground(presentAttTable.getBackground()); } } return label; }; for (int i = 1; i <= 4; i++) { presentAttTable.getColumnModel().getColumn(i).setCellRenderer(renderer); } TableColumn col = presentAttTable.getColumnModel().getColumn(0); col.setCellRenderer((table, value, isSelected, hasFocus, row, column) -> { JPanel localPnl = new JPanel(); localPnl.add(new JLabel(Data.getInstance().getIcon("attendee_40x40.png"))); if (isSelected) { localPnl.setBackground(presentAttTable.getSelectionBackground()); } else { if (row % 2 == 0) { localPnl.setBackground(UI.TABLE_ALT_COLOR); } else { localPnl.setBackground(presentAttTable.getBackground()); } } return localPnl; }); presentAttTable.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { updateAttButtons(); } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); scrllP = GUITools.setIntoScrollPane(presentAttTable); scrllP.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); scrllP.setToolTipText(translate("Add Attendee to Meeting")); scrllP.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (isAddResiAttPossible()) { ActionRegistry.getInstance().get(AddResiAttToProtAction.class.getName()).actionPerformed(null); } else { ActionRegistry.getInstance().get(AddAttToProtAction.class.getName()).actionPerformed(null); } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); JLabel labelAttendees = new JLabel(translate("Attendees of the current meeting:")); labelAttendees.setFont(UI.HUGE_FONT_BOLD); GUITools.addComponent(attPanel, gbl, labelAttendees, 0, 0, 2, 1, 1.0, 0.0, 20, 20, 0, 20, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST); GUITools.addComponent(attPanel, gbl, scrllP, 0, 1, 1, 1, 1.0, 1.0, 20, 20, 0, 20, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST); GUITools.addComponent(attPanel, gbl, attendeeButtons, 1, 1, 1, 1, 0, 0, 20, 0, 20, 20, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST); }
From source file:org.yccheok.jstock.gui.JTableUtilities.java
/** * Sets the editor/renderer for Date objects to provided JTable, for the specified column. * @param table JTable to set up//from w w w. ja v a2 s . c o m * @param row Column to apply */ public static void setDateEditorAndRendererForRow(JTable table, int row) { final TableColumn column = table.getColumnModel().getColumn(row); // SwingX's. Pretty but buggy. //column.setCellEditor(new DatePickerCellEditor()); column.setCellEditor(new DateFieldTableEditor()); final DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT); column.setCellRenderer(new DateRendererDecoratorEx(column.getCellRenderer(), format)); }
From source file:pipeline.GUI_utils.JXTablePerColumnFiltering.java
public JXTablePerColumnFiltering(TableModel model) { super(model); this.model = (BeanTableModel<?>) model; // Create the 1-row filtering Table nColumns = model.getColumnCount();/*from w w w.ja v a 2s. c o m*/ // DependencyEngine e = new DependencyEngine(new BasicEngineProvider()); for (int row = 0; row < model.getRowCount(); row++) { for (int i = 0; i < nColumns; i++) { if (getColumnName(i).contains("userCell")) { // this is a column with cells that can contain formulas in addition to computed values } else { } } } filteringModel = new DefaultTableModel(1, nColumns); initializeFilterModel(); filteringTable = new JXTableBetterFocus(filteringModel); filteringTable.setTableHeader(null); for (int i = 0; i < nColumns; i++) { TableColumn fColumn = filteringTable.getColumn(i); MultiRenderer multiRenderer = getMultiRenderer(); fColumn.setCellRenderer(multiRenderer); fColumn.setCellEditor(multiRenderer); fColumn.setWidth(getColumn(i).getWidth()); } this.setRowFilter(filter); JTableHeader header = this.getTableHeader(); if (tips == null) { tips = new ColumnHeaderToolTips(); } header.addMouseMotionListener(tips); }
From source file:unikn.dbis.univis.visualization.pivottable.VPivotTable.java
private void createPivotTable(boolean dataOnly) { // Removes the scroll pane that contains the pivottable. if (tableScrollPane != null) { remove(tableScrollPane);//from w w w. j a v a 2s . co m } // JTable anlegen mit Daten sowie Ueberschriften uniData = new VPivotTableData(cube, measure, function); Vector vectorData = uniData.getPivottableData(xAxisDimensions, yAxisDimensions); Vector vectorHeader = uniData.getPivottableHeader(xAxisDimensions, yAxisDimensions); // Sind denn ueberhaupt Daten zurueckgekommen? boolean dataGiven = ((vectorData != null) && (vectorData.size() > 0)); boolean headerDataGiven = ((vectorHeader != null && vectorHeader.size() > 0)); if (!dataGiven) { System.out.println("keine Daten!"); } if (!headerDataGiven) { System.out.println("keine Ueberschriften!"); } if (dataGiven & headerDataGiven) { VPivotTableModel modelOrigin = new VPivotTableModel(vectorData, vectorHeader); if (dataOnly) { tableSorter = new VTableSorter(modelOrigin); pivotTable = new JTable(tableSorter); tableSorter.setTableHeader(pivotTable.getTableHeader()); } else { VEnvelopeTableModel modelEnv = new VEnvelopeTableModel(modelOrigin); pivotTable = new JTable(modelEnv); modelEnv.setTableHeader(pivotTable.getTableHeader()); } SimpleRenderer renderer = new VNumberRenderer(false); pivotTable.setDefaultRenderer(String.class, renderer); // reine Number-Klasse hat Doubles nicht gefaerbt! // pivotTable.setDefaultRenderer(Number.class, renderer); pivotTable.setDefaultRenderer(Integer.class, renderer); pivotTable.setDefaultRenderer(Long.class, renderer); pivotTable.setDefaultRenderer(Double.class, renderer); // spezieller CellRenderer fr letzte Total-Spalte TableColumn col = pivotTable.getColumnModel().getColumn(vectorHeader.size() - 1); col.setCellRenderer(new VTotalCellRenderer()); /* *** Second Row --> Content Area *** */ pivotTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); //Set up tool tips for column headers. // pivotTable.getTableHeader().setToolTipText( // "Click to specify sorting; Control-Click to specify secondary sorting"); /* *** Second Row --> Content Area *** */ pivotTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); tableScrollPane = new JScrollPane(pivotTable); tableScrollPane.setVerticalScrollBar(new JScrollBar()); add(tableScrollPane, BorderLayout.CENTER); validate(); repaint(); } }