List of usage examples for javax.swing.table TableColumn setHeaderRenderer
@BeanProperty(description = "The header renderer.") public void setHeaderRenderer(TableCellRenderer headerRenderer)
TableCellRenderer
used to draw the TableColumn
's header to headerRenderer
. From source file:net.sf.keystore_explorer.gui.dialogs.extensions.DViewExtensions.java
private void initComponents() { ExtensionsTableModel extensionsTableModel = new ExtensionsTableModel(); jtExtensions = new JKseTable(extensionsTableModel); TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(extensionsTableModel); sorter.setComparator(2, new ObjectIdComparator()); jtExtensions.setRowSorter(sorter);//from w ww . j a v a 2s. c o m jtExtensions.setShowGrid(false); jtExtensions.setRowMargin(0); jtExtensions.getColumnModel().setColumnMargin(0); jtExtensions.getTableHeader().setReorderingAllowed(false); jtExtensions.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS); jtExtensions.setRowHeight(Math.max(18, jtExtensions.getRowHeight())); for (int i = 0; i < jtExtensions.getColumnCount(); i++) { TableColumn column = jtExtensions.getColumnModel().getColumn(i); column.setHeaderRenderer( new ExtensionsTableHeadRend(jtExtensions.getTableHeader().getDefaultRenderer())); column.setCellRenderer(new ExtensionsTableCellRend()); } TableColumn criticalCol = jtExtensions.getColumnModel().getColumn(0); criticalCol.setResizable(false); criticalCol.setMinWidth(28); criticalCol.setMaxWidth(28); criticalCol.setPreferredWidth(28); ListSelectionModel selectionModel = jtExtensions.getSelectionModel(); selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); selectionModel.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { try { CursorUtil.setCursorBusy(DViewExtensions.this); updateExtensionValue(); } finally { CursorUtil.setCursorFree(DViewExtensions.this); } } } }); jspExtensionsTable = PlatformUtil.createScrollPane(jtExtensions, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); jspExtensionsTable.getViewport().setBackground(jtExtensions.getBackground()); jpExtensionsTable = new JPanel(new BorderLayout(5, 5)); jpExtensionsTable.setPreferredSize(new Dimension(500, 200)); jpExtensionsTable.add(jspExtensionsTable, BorderLayout.CENTER); jpExtensionValue = new JPanel(new BorderLayout(5, 5)); jlExtensionValue = new JLabel(res.getString("DViewExtensions.jlExtensionValue.text")); jpExtensionValue.add(jlExtensionValue, BorderLayout.NORTH); jepExtensionValue = new JEditorPane(); jepExtensionValue.setFont(new Font(Font.MONOSPACED, Font.PLAIN, LnfUtil.getDefaultFontSize())); jepExtensionValue.setEditable(false); jepExtensionValue.setToolTipText(res.getString("DViewExtensions.jtaExtensionValue.tooltip")); // JGoodies - keep uneditable color same as editable jepExtensionValue.putClientProperty("JTextArea.infoBackground", Boolean.TRUE); // for displaying URLs in extensions as clickable links jepExtensionValue.setContentType("text/html"); jepExtensionValue.addHyperlinkListener(this); // use default font and foreground color from the component jepExtensionValue.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); jspExtensionValue = PlatformUtil.createScrollPane(jepExtensionValue, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); jpExtensionValueTextArea = new JPanel(new BorderLayout(5, 5)); jpExtensionValueTextArea.setPreferredSize(new Dimension(500, 200)); jpExtensionValueTextArea.add(jspExtensionValue, BorderLayout.CENTER); jpExtensionValue.add(jpExtensionValueTextArea, BorderLayout.CENTER); jbAsn1 = new JButton(res.getString("DViewExtensions.jbAsn1.text")); PlatformUtil.setMnemonic(jbAsn1, res.getString("DViewExtensions.jbAsn1.mnemonic").charAt(0)); jbAsn1.setToolTipText(res.getString("DViewExtensions.jbAsn1.tooltip")); jbAsn1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { try { CursorUtil.setCursorBusy(DViewExtensions.this); asn1DumpPressed(); } finally { CursorUtil.setCursorFree(DViewExtensions.this); } } }); jpExtensionValueAsn1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); jpExtensionValueAsn1.add(jbAsn1); jpExtensionValue.add(jpExtensionValueAsn1, BorderLayout.SOUTH); jpExtensions = new JPanel(new GridLayout(2, 1, 5, 5)); jpExtensions.setBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new CompoundBorder(new EtchedBorder(), new EmptyBorder(5, 5, 5, 5)))); jpExtensions.add(jpExtensionsTable); jpExtensions.add(jpExtensionValue); jbOK = new JButton(res.getString("DViewExtensions.jbOK.text")); jbOK.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { okPressed(); } }); jpOK = PlatformUtil.createDialogButtonPanel(jbOK, false); extensionsTableModel.load(extensions); if (extensionsTableModel.getRowCount() > 0) { jtExtensions.changeSelection(0, 0, false, false); } getContentPane().add(jpExtensions, BorderLayout.CENTER); getContentPane().add(jpOK, BorderLayout.SOUTH); setResizable(false); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent evt) { closeDialog(); } }); getRootPane().setDefaultButton(jbOK); pack(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jbOK.requestFocus(); } }); }
From source file:com.sec.ose.osi.ui.frm.main.manage.ManagedProjectTableModel.java
public void setColumnType(JTable table) { table.setShowVerticalLines(false);//ww w. j av a2 s. c o m table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setRowHeight(30); JTableHeader header = table.getTableHeader(); header.setPreferredSize(new java.awt.Dimension(table.getTableHeader().getWidth(), 30)); header.setFont(new Font("Arial", Font.BOLD, 12)); header.setReorderingAllowed(false); TableColumnModel cm = table.getColumnModel(); TableColumn col = null; analyzeHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ANALYZE_TARGET), "Analyze Target"); col = cm.getColumn(COL_ANALYZE_TARGET); col.setHeaderRenderer(analyzeHeader); JCheckBox chkbox = new JCheckBox(); chkbox.setBackground(Color.white); chkbox.setHorizontalAlignment(JLabel.CENTER); col.setCellRenderer(new DefaultTableCellRenderer() { private static final long serialVersionUID = 1L; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { ManagedProjectTableModel model = (ManagedProjectTableModel) table.getModel(); String sPrjName = (String) table.getValueAt(row, ManagedProjectTableModel.COL_PROJECT_NAME); OSIProjectInfo item = model.getProjectInfo(sPrjName); JCheckBox chkbox = new JCheckBox(); chkbox.setSelected(((Boolean) value).booleanValue()); if (item != null) { chkbox.setEnabled(item.isLocationValid()); } chkbox.setHorizontalAlignment(JLabel.CENTER); chkbox.setBackground(Color.white); return (Component) chkbox; } }); col.setCellEditor(new DefaultCellEditor(chkbox)); col = cm.getColumn(COL_ANALYZE_STATUS); col.setCellRenderer(new StatusIconCellRenderer()); col = cm.getColumn(COL_SOURCE_LOCATION); col.setCellRenderer(new FileBrowseCellRenderer()); col.setCellEditor(new FileBrowseCellEditor()); }
From source file:com.qspin.qtaste.ui.xmleditor.TestRequirementEditor.java
public void addColumn(String header) { m_TestRequirementModel.addColumn(header); TableColumn hcol = m_TestRequirementTable.getColumn(header); hcol.setHeaderRenderer(new MyTableHeaderRenderer()); hcol.setCellEditor(new TestDataTableCellEditor()); computeColumnWidths();//from w ww . j a va 2s . co m setModified(true); // now add the needed rows }
From source file:com.qspin.qtaste.ui.xmleditor.TestRequirementEditor.java
public void loadXMLFile(String fileName) { try {/*w ww.j a v a 2s . c o m*/ m_TestRequirementModel.removeTableModelListener(tableListener); m_TestRequirementTable.getColumnModel().removeColumnModelListener(m_TableColumnModelListener); XMLFile xmlFile = new XMLFile(fileName); m_TestRequirementModel.setRowCount(0); m_TestRequirementModel.setColumnCount(0); currentXMLFile = fileName; m_TestRequirementModel.setRequirements(xmlFile.getXMLDataSet()); Enumeration<TableColumn> columns = m_TestRequirementTable.getColumnModel().getColumns(); while (columns.hasMoreElements()) { TableColumn hcol = columns.nextElement(); hcol.setHeaderRenderer(new MyTableHeaderRenderer()); hcol.setCellEditor(new TestDataTableCellEditor()); } computeColumnWidths(); m_TestRequirementTable.doLayout(); m_TestRequirementModel.addTableModelListener(tableListener); m_TestRequirementTable.getColumnModel().addColumnModelListener(m_TableColumnModelListener); } catch (IOException ex) { logger.error(ex.getMessage()); } catch (SAXException ex) { logger.error(ex.getMessage()); } catch (ParserConfigurationException ex) { logger.error(ex.getMessage()); } }
From source file:com.qspin.qtaste.ui.xmleditor.TestRequirementEditor.java
private void computeColumnWidths() { // horizontal spacing int hspace = 6; TableModel model = m_TestRequirementTable.getModel(); // rows no/*from w w w . j av a 2 s .c o m*/ int cols = model.getColumnCount(); // columns no int rows = model.getRowCount(); // width vector int w[] = new int[model.getColumnCount()]; // computes headers widths for (int i = 0; i < cols; i++) { w[i] = (int) m_TestRequirementTable .getDefaultRenderer(String.class).getTableCellRendererComponent(m_TestRequirementTable, m_TestRequirementModel.getColumnName(i), false, false, -1, i) .getPreferredSize().getWidth() + hspace; TableColumn hcol = m_TestRequirementTable.getColumn(m_TestRequirementModel.getColumnName(i)); hcol.setHeaderRenderer(new MyTableHeaderRenderer()); } // check if cell values fit in their cells and if not // keep in w[i] the necessary with for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { Object o = model.getValueAt(i, j); int width = 0; if (o != null) { width = (int) m_TestRequirementTable.getCellRenderer(i, j) .getTableCellRendererComponent(m_TestRequirementTable, o, false, false, i, j) .getPreferredSize().getWidth() + hspace; } if (w[j] < width) { w[j] = width; } } } TableColumnModel colModel = m_TestRequirementTable.getColumnModel(); // and finally setting the column widths for (int i = 0; i < cols; i++) { colModel.getColumn(i).setPreferredWidth(w[i]); } }
From source file:net.kamhon.ieagle.swing.table.KTable.java
private void initComponents(List<KTableColumn> columns) { tableModel = new KTableModel<T>(this, columns); setModel(tableModel);/*from ww w . j a v a 2s . co m*/ // final KTable<T> table = this; for (int i = 0; i < columns.size(); i++) { KTableColumn column = columns.get(i); TableColumn tc = columnModel.getColumn(i); tc.setHeaderValue(column.getColumnLabel()); if (column instanceof KTableCheckBoxColumn) { BooleanEditor cellEditor = new BooleanEditor(); if (column instanceof KTableRowCheckBoxColumn) { /*final JCheckBox component = (JCheckBox) cellEditor.getComponent(); component.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int[] selectedRows = table.getSelectedRows(); int selectedRow = table.getSelectedRow(); log.debug("selectedRows = " + selectedRows); log.debug("selectedRow = " + selectedRow); if (component.isSelected()) { } } });*/ // log.debug("component = " + component); } tc.setCellEditor(cellEditor); tc.setCellRenderer(this.getDefaultRenderer(Boolean.class)); tc.setHeaderRenderer(new KTableHeaderCheckBox(this)); } else if (column instanceof KTableTextColumn) { KTextField textField = new KTextField(); textField.setEditable(false); tc.setCellEditor(new GenericEditor(textField)); } } setColumnControlVisible(true); setShowGrid(false, false); }
From source file:com.aw.swing.mvp.binding.component.BndSJTable.java
/** * Configure the grid columns based on the ColumnInfo information *//*w ww .java2 s. co m*/ protected void configureColumns() { //jcv:2.0.1 // TableCellRenderer tableCellRenderer = createHeaderRenderer(); JTableHeader jTableHeader = jTable.getTableHeader(); TableCellRenderer tableCellRenderer = jTableHeader.getDefaultRenderer(); for (int i = 0; i < columnsInfo.length; i++) { TableColumn col = jTable.getColumnModel().getColumn(i); if (columnsInfo[i] instanceof SelectorColumn) { final SelectorColumn selectorColumn = (SelectorColumn) columnsInfo[i]; // Set special renderer for the column's header col.setHeaderRenderer(getSelectorHeaderRenderer(selectorColumn)); } else { // Set special renderer for the column's header col.setHeaderRenderer(tableCellRenderer); } // set column width if (columnsInfo[i].getWidth() > 0) { col.setPreferredWidth(columnsInfo[i].getWidth()); } if (columnsInfo[i].isEditable() || StringUtils.hasText(columnsInfo[i].getValidationRule())) { columnsInfo[i].initializeValidator(); } // set column alignment if the cell is not editable if (!columnsInfo[i].isEditable() && !(columnsInfo[i] instanceof ButtonColumn)) { configureReadOnlyCell(col, columnsInfo[i]); } else { configureEditableCell(col, columnsInfo[i]); } columnsInfo[i].setIdx(i); } if (fixedColumns > 0) { fixedColumnTableMgr = FixedColumnTableDecorator.decorate(getJTable(), fixedColumns); JTable fixedTable = fixedColumnTableMgr.getFixedTable(); JTableMouseProcessor jTableMouseProcessor = new JTableMouseProcessor(presenter, this, gridIndex); jTableMouseProcessor.setJTable(fixedTable); jTableMouseProcessor.setInFixedTable(true); fixedTable.addMouseListener(getJTableMouseListener(jTableMouseProcessor)); fixedTable.getTableHeader().addMouseListener(getJTableHeaderMouseListener(jTableMouseProcessor)); } }
From source file:org.isatools.isacreator.gui.formelements.SubForm.java
public boolean addColumn() { DefaultTableModel model = (DefaultTableModel) scrollTable.getModel(); TableColumn col = new TableColumn(scrollTable.getModel().getColumnCount()); col.setHeaderRenderer(scrollTableHeaderRenderer); SpreadsheetUtils.stopCellEditingInTable(scrollTable); return doAddColumn(model, col); }
From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java
/** * Adds a column to the table with a specified name * * @param headerLabel - name of column to be added *//*from w w w . j av a2s .c om*/ public TableColumn addColumn(Object headerLabel, boolean required) { SpreadsheetModel model = (SpreadsheetModel) spreadsheet.getTable().getModel(); TableColumn newColumn = new TableColumn(spreadsheet.getTable().getModel().getColumnCount()); newColumn.setHeaderValue(headerLabel); newColumn.setPreferredWidth(calcColWidths(headerLabel.toString())); newColumn.setHeaderRenderer(spreadsheet.columnRenderer); // add a cell editor (if available to the column) addCellEditor(newColumn); model.addToColumns(headerLabel.toString()); model.addColumn(headerLabel.toString()); spreadsheet.getTable().addColumn(newColumn); addFieldToRequiredCellRendererIfVisible(required, newColumn.getModelIndex()); model.fireTableStructureChanged(); model.fireTableDataChanged(); if (spreadsheet.getTable().getRowCount() > 0) { spreadsheet.getTable().setValueAt( spreadsheet.getTableReferenceObject().getDefaultValue(headerLabel.toString()), 0, spreadsheet.getTable().getColumnCount() - 1); copyColumnDownwards(0, spreadsheet.getTable().getColumnCount() - 1); spreadsheet.getTableReferenceObject().getDefaultValue(headerLabel.toString()); } spreadsheet.getTable().addNotify(); return newColumn; }
From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java
/** * Add a column after the currently selected column * * @param headerLabel - name of column to add. * @param fixedVal - initial value to populate column with, if any. * @param currentlySelectedColumn - place in table to add the column after. *//*from w ww . j a v a 2 s.c om*/ public TableColumn addColumnAfterPosition(Object headerLabel, String fixedVal, boolean required, int currentlySelectedColumn) { if (currentlySelectedColumn == -1) { currentlySelectedColumn = (spreadsheet.getTable().getSelectedColumn() == -1) ? (spreadsheet.getTable().getColumnCount() - 1) : spreadsheet.getTable().getSelectedColumn(); } SpreadsheetModel model = (SpreadsheetModel) spreadsheet.getTable().getModel(); int columnCount = spreadsheet.getTable().getModel().getColumnCount(); TableColumn col = new TableColumn(columnCount); col.setHeaderValue(headerLabel); col.setPreferredWidth(calcColWidths(headerLabel.toString())); col.setHeaderRenderer(spreadsheet.columnRenderer); addFieldToRequiredCellRendererIfVisible(required, columnCount); addCellEditor(col); model.addToColumns(headerLabel.toString()); model.addColumn(col); spreadsheet.getTable().addColumn(col); model.fireTableStructureChanged(); model.fireTableDataChanged(); // now move the column into its correct position int stopValue = headerLabel.toString().equals("Unit") ? (spreadsheet.previouslyAddedCharacteristicPosition + 1) : (currentlySelectedColumn + 1); for (int i = spreadsheet.getTable().getColumnCount() - 1; i > stopValue; i--) { spreadsheet.getTable().getColumnModel().moveColumn(i - 1, i); } addDependentColumn(headerLabel, currentlySelectedColumn, col); if (headerLabel.toString().contains("Characteristics") || headerLabel.toString().contains("Factor") || headerLabel.toString().contains("Parameter")) { spreadsheet.previouslyAddedCharacteristicPosition = stopValue; } propagateDefaultValue(fixedVal, stopValue); spreadsheet.getTable().addNotify(); return col; }