List of usage examples for javax.swing.table TableColumnModel getColumn
public TableColumn getColumn(int columnIndex);
TableColumn
object for the column at columnIndex
. From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.FileSelectionTable.java
/** * Helper method to sets the table header with the specified index to the * renderer provided./*from www . ja v a2s.c om*/ * @param columnModel The <see>TableColumnModel</see> to use * @param columnIndex The index of the column to set * @param renderer The renderer to set */ private void setHeaderRenderer(TableColumnModel columnModel, int columnIndex, TableCellRenderer renderer) { TableColumn column = columnModel.getColumn(columnIndex); column.setHeaderRenderer(renderer); }
From source file:org.paxle.desktop.impl.dialogues.cconsole.CrawlingConsole.java
private final int[] getCurrentWidths() { final TableColumnModel tcm = table.getTableHeader().getColumnModel(); final int[] widths = new int[tcm.getColumnCount()]; for (int i = 0; i < widths.length; i++) widths[i] = tcm.getColumn(i).getWidth(); return widths; }
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 ww w. java 2 s. c om * 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;/* www .j a v a 2s. c o m*/ 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.quackbot.gui.InfoPlugins.java
public InfoPlugins(final Controller controller) { super();// ww w . ja v a 2 s . com setBorder(BorderFactory.createTitledBorder("Active plugins")); //Configure the table model pluginTableModel = new DefaultTableModel() { @Override public Class getColumnClass(int c) { return getValueAt(0, c).getClass(); } }; pluginTableModel.addColumn("Name"); pluginTableModel.addColumn("Type"); pluginTableModel.addColumn("Enabled"); pluginTableModel.addColumn("Admin Only"); pluginTableModel.addColumn("Required"); pluginTableModel.addColumn("Optional"); pluginTableModel.addColumn("Help"); //Toggle command enabled status when changed on the table pluginTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (e.getType() != TableModelEvent.UPDATE) return; TableModel model = ((TableModel) e.getSource()); String plugin = StringUtils .trimToNull((String) ((TableModel) e.getSource()).getValueAt(e.getFirstRow(), 0)); Command command = controller.getHookManager().getCommand(plugin); if (command != null) { command.setEnabled((Boolean) model.getValueAt(e.getFirstRow(), 1)); log.debug((command.isEnabled() ? "Enabled" : "Disabled") + " command " + command.getName()); } } }); //Configure the table pluginTable = new JTable(pluginTableModel) { @Override public String getToolTipText(MouseEvent e) { Point p = e.getPoint(); int rowIndex = pluginTable.rowAtPoint(p); int colIndex = pluginTable.columnAtPoint(p); if ((colIndex == 0 || colIndex == 5 || colIndex == 6) && getValueAt(rowIndex, colIndex) != null) return getValueAt(rowIndex, colIndex).toString(); return ""; } }; pluginTable.setRowSelectionAllowed(false); pluginTable.setColumnSelectionAllowed(false); pluginTable.setCellSelectionEnabled(false); pluginTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); //Configure the default column widths TableColumnModel columnModel = pluginTable.getColumnModel(); columnModel.getColumn(0).setPreferredWidth(120); columnModel.getColumn(1).setPreferredWidth(50); columnModel.getColumn(2).setPreferredWidth(75); columnModel.getColumn(3).setPreferredWidth(50); columnModel.getColumn(4).setPreferredWidth(40); columnModel.getColumn(5).setPreferredWidth(520); //Add the table to the scroll pane add(pluginTable); //Get notified of hook changes controller.getHookManager().addHook(new QListener("QBGuiPluginPanel") { @Override public void onHookLoad(HookLoadEvent event) { //TODO: Inform user about exception if (event.getException() != null) return; QListener hook = event.getHook(); if (hook instanceof Command) { Command command = (Command) hook; pluginTableModel.addRow( new Object[] { command.getName(), "Command", command.isEnabled(), command.isAdmin(), command.getRequiredParams(), command.getOptionalParams(), command.getHelp() }); } else { pluginTableModel.addRow(new Object[] { hook.getName(), "Hook", null, null, null, null, null }); } } @Override public void onHookLoadStart(HookLoadStartEvent event) { pluginTableModel.setRowCount(0); } }); }
From source file:org.richie.codeGen.ui.configui.ConstantConfigWin.java
public JScrollPane getCenterPanel() { if (centerPanel == null) { constantConfigModel = new ConstantConfigModel(); table = new JTable(constantConfigModel); table.setBackground(Color.white); table.setSelectionBackground(Color.white); table.setSelectionForeground(Color.black); JTableHeader tableHeader = table.getTableHeader(); tableHeader.setReorderingAllowed(false);// ?? table.setFont(new Font("Dialog", 0, 13)); table.setRowHeight(23);/*from ww w.j a v a 2 s. co m*/ TemplateConfigWin.hideColumn(table, 3); JComboBox cm = new JComboBox(GlobalData.costantType); TableColumnModel tcm = table.getColumnModel(); tcm.getColumn(4).setCellRenderer(new ButtonRenderer()); tcm.getColumn(4).setCellEditor(new ButtonEditor()); tcm.getColumn(1).setCellEditor(new DefaultCellEditor(cm)); tcm.getColumn(0).setPreferredWidth(50); tcm.getColumn(1).setPreferredWidth(30); tcm.getColumn(2).setPreferredWidth(240); tcm.getColumn(4).setPreferredWidth(20); centerPanel = new JScrollPane(table); // table addTableListener(); } return centerPanel; }
From source file:org.richie.codeGen.ui.GenAndPreviewUI.java
public JScrollPane getTemplatePanel() { complateModel = new CodeTemplateModel(false); table = new JTable(complateModel); table.setBackground(Color.white); table.setSelectionBackground(Color.white); table.setSelectionForeground(Color.black); JTableHeader tableHeader = table.getTableHeader(); tableHeader.setReorderingAllowed(false);// ?? table.setFont(new Font("Dialog", 0, 13)); table.setRowHeight(23);//from w w w .ja v a 2s . com try { templateNames = GlobalData.getTemplateNames(); rootPathNames = GlobalData.getOutFileRootNames(); } catch (Exception e) { log.error("??", e); } templateNameCom = new JComboBox(templateNames); rootPathCom = new JComboBox(rootPathNames); // ?? TemplateConfigWin.hideColumn(table, 8); TableColumnModel tcm = table.getColumnModel(); tcm.getColumn(1).setCellEditor(new DefaultCellEditor(templateNameCom)); tcm.getColumn(3).setCellEditor(new DefaultCellEditor(rootPathCom)); tcm.getColumn(7).setCellRenderer(new ButtonRenderer()); tcm.getColumn(7).setCellEditor(new ButtonEditor()); tcm.getColumn(9).setCellRenderer(new ButtonRenderer()); tcm.getColumn(9).setCellEditor(new ButtonEditor()); tcm.getColumn(0).setMaxWidth(40); tcm.getColumn(1).setPreferredWidth(50); tcm.getColumn(2).setPreferredWidth(30); tcm.getColumn(3).setPreferredWidth(40); tcm.getColumn(4).setPreferredWidth(120); tcm.getColumn(5).setMinWidth(90); tcm.getColumn(5).setMaxWidth(90); tcm.getColumn(6).setPreferredWidth(10); tcm.getColumn(7).setMaxWidth(60); tcm.getColumn(7).setMinWidth(60); tcm.getColumn(9).setMaxWidth(60); tcm.getColumn(9).setMinWidth(60); JScrollPane tablePanel = new JScrollPane(table); // table addTableListener(); return tablePanel; }
From source file:org.richie.codeGen.ui.GenAndPreviewUI.java
public void refreshComBoBox() { try {/*ww w. ja v a 2 s.c om*/ templateNames = GlobalData.getTemplateNames(); rootPathNames = GlobalData.getOutFileRootNames(); } catch (Exception ex) { ex.printStackTrace(); } templateNameCom = new JComboBox(templateNames); TableColumnModel tcm = table.getColumnModel(); tcm.getColumn(1).setCellEditor(new DefaultCellEditor(templateNameCom)); templateNameCom.updateUI(); rootPathCom = new JComboBox(rootPathNames); TableColumnModel tcm1 = table.getColumnModel(); tcm1.getColumn(3).setCellEditor(new DefaultCellEditor(rootPathCom)); rootPathCom.updateUI(); }
From source file:org.svv.acmate.gui.ACTestingPanel.java
private void resizeColumnWidth(JTable table) { final TableColumnModel columnModel = table.getColumnModel(); for (int column = 0; column < table.getColumnCount(); column++) { int width = 80; // Min width for (int row = 0; row < table.getRowCount(); row++) { TableCellRenderer renderer = table.getCellRenderer(row, column); Component comp = table.prepareRenderer(renderer, row, column); width = Math.max(comp.getPreferredSize().width + 1, width); }//w w w. ja v a 2s . c o m columnModel.getColumn(column).setPreferredWidth(width); } }
From source file:org.yccheok.jstock.gui.JTableUtilities.java
public static void makeTableColumnWidthFit(JTable jTable, int col, int margin, boolean locking) { // strategy - get max width for cells in column and // make that the preferred width TableColumnModel columnModel = jTable.getColumnModel(); int maxwidth = 0; for (int row = 0; row < jTable.getRowCount(); row++) { TableCellRenderer rend = jTable.getCellRenderer(row, col); Object value = jTable.getValueAt(row, col); Component comp = rend.getTableCellRendererComponent(jTable, value, false, false, row, col); maxwidth = Math.max(comp.getPreferredSize().width + margin, maxwidth); } // for row/*from ww w . ja va 2s .c om*/ TableColumn column = columnModel.getColumn(col); TableCellRenderer headerRenderer = column.getHeaderRenderer(); if (headerRenderer == null) { headerRenderer = jTable.getTableHeader().getDefaultRenderer(); } Object headerValue = column.getHeaderValue(); Component headerComp = headerRenderer.getTableCellRendererComponent(jTable, headerValue, false, false, 0, col); maxwidth = Math.max(maxwidth, headerComp.getPreferredSize().width + margin); column.setPreferredWidth(maxwidth); if (locking) { // User will not able to adjust the width manually. column.setMinWidth(maxwidth); column.setMaxWidth(maxwidth); } }