List of usage examples for javax.swing JTable getColumn
public TableColumn getColumn(Object identifier)
TableColumn
object for the column in the table whose identifier is equal to identifier
, when compared using equals
. From source file:org.apache.jmeter.protocol.http.gui.HTTPArgumentsPanel.java
@Override protected void sizeColumns(JTable table) { GuiUtils.fixSize(table.getColumn(INCLUDE_EQUALS), table); GuiUtils.fixSize(table.getColumn(ENCODE_OR_NOT), table); }
From source file:org.apache.jmeter.protocol.http.visualizers.RequestViewHTTP.java
private void setFirstColumnPreferredAndMaxWidth(JTable table) { TableColumn column = table.getColumnModel().getColumn(0); column.setMaxWidth(300);//from w w w . ja v a 2s . c om column.setPreferredWidth(160); }
From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java
private JTable createTable(final ViewState state) { JTable table; final ModelGraph selected = state.getSelected(); if (selected != null) { final Vector<Vector<String>> rows = new Vector<Vector<String>>(); ConcurrentHashMap<String, String> keyToGroupMap = new ConcurrentHashMap<String, String>(); Metadata staticMet = selected.getModel().getStaticMetadata(); Metadata inheritedMet = selected.getInheritedStaticMetadata(state); Metadata completeMet = new Metadata(); if (staticMet != null) { completeMet.replaceMetadata(staticMet.getSubMetadata(state.getCurrentMetGroup())); }// w w w . j av a 2 s.c o m if (selected.getModel().getExtendsConfig() != null) { for (String configGroup : selected.getModel().getExtendsConfig()) { Metadata extendsMetadata = state.getGlobalConfigGroups().get(configGroup).getMetadata() .getSubMetadata(state.getCurrentMetGroup()); for (String key : extendsMetadata.getAllKeys()) { if (!completeMet.containsKey(key)) { keyToGroupMap.put(key, configGroup); completeMet.replaceMetadata(key, extendsMetadata.getAllMetadata(key)); } } } } if (inheritedMet != null) { Metadata inheritedMetadata = inheritedMet.getSubMetadata(state.getCurrentMetGroup()); for (String key : inheritedMetadata.getAllKeys()) { if (!completeMet.containsKey(key)) { keyToGroupMap.put(key, "__inherited__"); completeMet.replaceMetadata(key, inheritedMetadata.getAllMetadata(key)); } } } List<String> keys = completeMet.getAllKeys(); Collections.sort(keys); for (String key : keys) { if (key.endsWith("/envReplace")) { continue; } String values = StringUtils.join(completeMet.getAllMetadata(key), ","); Vector<String> row = new Vector<String>(); row.add(keyToGroupMap.get(key)); row.add(key); row.add(values); row.add(Boolean.toString(Boolean.parseBoolean(completeMet.getMetadata(key + "/envReplace")))); rows.add(row); } table = new JTable();// rows, new Vector<String>(Arrays.asList(new // String[] { "key", "values", "envReplace" }))); table.setModel(new AbstractTableModel() { public String getColumnName(int col) { switch (col) { case 0: return "group"; case 1: return "key"; case 2: return "values"; case 3: return "envReplace"; default: return null; } } public int getRowCount() { return rows.size() + 1; } public int getColumnCount() { return 4; } public Object getValueAt(int row, int col) { if (row >= rows.size()) { return null; } String value = rows.get(row).get(col); if (value == null && col == 3) { return "false"; } if (value == null && col == 0) { return "__local__"; } return value; } public boolean isCellEditable(int row, int col) { if (row >= rows.size()) { return selected.getModel().getStaticMetadata().containsGroup(state.getCurrentMetGroup()); } if (col == 0) { return false; } String key = rows.get(row).get(1); return key == null || (selected.getModel().getStaticMetadata() != null && selected.getModel().getStaticMetadata().containsKey(getKey(key, state))); } public void setValueAt(Object value, int row, int col) { if (row >= rows.size()) { Vector<String> newRow = new Vector<String>( Arrays.asList(new String[] { null, null, null, null })); newRow.add(col, (String) value); rows.add(newRow); } else { Vector<String> rowValues = rows.get(row); rowValues.add(col, (String) value); rowValues.remove(col + 1); } this.fireTableCellUpdated(row, col); } }); MyTableListener tableListener = new MyTableListener(state); table.getModel().addTableModelListener(tableListener); table.getSelectionModel().addListSelectionListener(tableListener); } else { table = new JTable(new Vector<Vector<String>>(), new Vector<String>(Arrays.asList(new String[] { "key", "values", "envReplace" }))); } // table.setFillsViewportHeight(true); table.setSelectionBackground(Color.cyan); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableCellRenderer cellRenderer = new TableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel field = new JLabel((String) value); if (column == 0) { field.setForeground(Color.gray); } else { if (isSelected) { field.setBorder(new EtchedBorder(1)); } if (table.isCellEditable(row, 1)) { field.setForeground(Color.black); } else { field.setForeground(Color.gray); } } return field; } }; TableColumn groupCol = table.getColumnModel().getColumn(0); groupCol.setPreferredWidth(75); groupCol.setCellRenderer(cellRenderer); TableColumn keyCol = table.getColumnModel().getColumn(1); keyCol.setPreferredWidth(200); keyCol.setCellRenderer(cellRenderer); TableColumn valuesCol = table.getColumnModel().getColumn(2); valuesCol.setPreferredWidth(300); valuesCol.setCellRenderer(cellRenderer); TableColumn envReplaceCol = table.getColumnModel().getColumn(3); envReplaceCol.setPreferredWidth(75); envReplaceCol.setCellRenderer(cellRenderer); table.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3 && DefaultPropView.this.table.getSelectedRow() != -1) { int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition()); String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state); Metadata staticMet = state.getSelected().getModel().getStaticMetadata(); override.setVisible(staticMet == null || !staticMet.containsKey(key)); delete.setVisible(staticMet != null && staticMet.containsKey(key)); tableMenu.show(DefaultPropView.this.table, e.getX(), e.getY()); } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); return table; }
From source file:org.kootox.episodesmanager.content.EpisodesListTableModel.java
public void update() { initValues();/*from w ww.j ava 2 s .c om*/ fireTableDataChanged(); if (ui != null) { JTable table = ui.getEpisodeslistTable(); TableColumn column = table.getColumn(_("episodesmanager.episode.actions")); column.setCellRenderer(new ButtonRenderer()); column.setCellEditor(new ButtonEditor(new JCheckBox())); } }
From source file:org.lockss.devtools.plugindef.EDPInspectorTableModel.java
public void setColumnSize(JTable table, int col) { TableColumn column = null;/* www . j a v a2 s.c om*/ Component comp = null; int headerWidth = 0; int cellWidth = 0; String longestStr = ""; String curString = ""; for (int row = 0; row < inspectorEntries.length; row++) { curString = data[row][col].toString(); if (curString.length() > longestStr.length()) { longestStr = curString; } } TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); column = table.getColumnModel().getColumn(col); comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; comp = table.getDefaultRenderer(getColumnClass(col)).getTableCellRendererComponent(table, longestStr, false, false, 0, col); cellWidth = comp.getPreferredSize().width; column.setPreferredWidth(Math.max(headerWidth, cellWidth)); }
From source file:org.nuclos.client.main.MainController.java
private Map<String, Map<String, Action>> getCommandMap() { HashMap<String, Map<String, Action>> res = new HashMap<String, Map<String, Action>>(); HashMap<String, Action> mainController = new HashMap<String, Action>(); /* that's too cumbersome: mainController.put(/*from w ww. j av a 2s . c o m*/ "cmdChangePassword", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cmdChangePassword(); } }); */ mainController.put("cmdDirectHelp", cmdDirectHelp); mainController.put("cmdShowPersonalTasks", cmdShowPersonalTasks); mainController.put("cmdShowTimelimitTasks", cmdShowTimelimitTasks); mainController.put("cmdShowPersonalSearchFilters", cmdShowPersonalSearchFilters); mainController.put("cmdChangePassword", cmdChangePassword); mainController.put("cmdOpenSettings", cmdOpenSettings); mainController.put("cmdOpenManagementConsole", cmdOpenManagementConsole); //mainController.put("cmdOpenEntityWizard", cmdOpenEntityWizard); mainController.put("cmdOpenRelationEditor", cmdOpenRelationEditor); mainController.put("cmdOpenCustomComponentWizard", cmdOpenCustomComponentWizard); //mainController.put("cmdRefreshClientCaches", cmdRefreshClientCaches); mainController.put("cmdSelectAll", cmdSelectAll); mainController.put("cmdHelpContents", cmdHelpContents); mainController.put("cmdShowAboutDialog", cmdShowAboutDialog); mainController.put("cmdShowProjectReleaseNotes", cmdShowProjectReleaseNotes); mainController.put("cmdShowNuclosReleaseNotes", cmdShowNuclosReleaseNotes); mainController.put("cmdLogoutExit", cmdLogoutExit); mainController.put("cmdWindowClosing", cmdWindowClosing); mainController.put("cmdExecuteRport", cmdExecuteRport); for (Method m : getClass().getDeclaredMethods()) { if (m.getName().startsWith("cmd")) { Class<?>[] pt = m.getParameterTypes(); if (pt.length == 0 || (pt.length == 1 && pt[0].isAssignableFrom(ActionEvent.class))) { final Method fm = m; Action a = new AbstractAction(m.getName()) { @Override public void actionPerformed(ActionEvent e) { miDelegator(e, fm); } }; mainController.put(m.getName(), a); } } } res.put("MainController", mainController); HashMap<String, Action> clipboardUtils = new HashMap<String, Action>(); clipboardUtils.put("cutAction", new ClipboardUtils.CutAction()); clipboardUtils.put("copyAction", new ClipboardUtils.CopyAction()); clipboardUtils.put("pasteAction", new ClipboardUtils.PasteAction()); res.put("ClipboardUtils", clipboardUtils); HashMap<String, Action> dev = new HashMap<String, Action>(); dev.put("jmsNotification", new AbstractAction("Test JMS notification") { @Override public void actionPerformed(ActionEvent e) { String s = JOptionPane.showInputDialog(getMainFrame(), "Topic: Message"); if (s == null) return; String[] a = s.split(": *"); if (a.length == 2) { // testFacadeRemote.testClientNotification(a[0], a[1]); throw new UnsupportedOperationException("TestFacade removed"); } else { JOptionPane.showMessageDialog(getMainFrame(), "Wrong input format"); } } }); dev.put("webPrefs", new AbstractAction("Test Web Prefs-Access") { @Override public void actionPerformed(ActionEvent e) { String s = JOptionPane.showInputDialog(getMainFrame(), "Access-Path"); if (s == null) return; try { Map<String, String> m = getWebAccessPrefs().getPrefsMap(s); StringBuilder sb = new StringBuilder(); for (String k : m.keySet()) sb.append(k).append(": ").append(m.get(k)).append("\n"); JOptionPane.showMessageDialog(getMainFrame(), sb.toString()); } catch (CommonBusinessException e1) { Errors.getInstance().showExceptionDialog(getMainFrame(), e1); } } }); dev.put("uiDefaults", new AbstractAction("UIDefaults") { @Override public void actionPerformed(ActionEvent e) { JFrame out = new JFrame("UIDefaults"); out.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); out.getContentPane().setLayout(new BorderLayout()); final UIDefTableModel mdl = new UIDefTableModel(); final JTable contentTable = new JTable(mdl); JScrollPane sp = new JScrollPane(contentTable); out.getContentPane().add(sp, BorderLayout.CENTER); UIDefaults defs = UIManager.getDefaults(); for (Object key : CollectionUtils.iterableEnum((defs.keys()))) mdl.add(key.toString(), defs.get(key)); mdl.sort(); contentTable.getColumnModel().getColumn(1).setCellRenderer(new UIDefaultsRenderer()); contentTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int row = contentTable.rowAtPoint(e.getPoint()); mdl.forceValue(contentTable.convertRowIndexToModel(row)); } }); out.pack(); out.setVisible(true); } }); dev.put("checkJawin", new AbstractAction("Check Jawin") { @Override public void actionPerformed(ActionEvent e) { try { SystemUtils.checkJawin(); JOptionPane.showMessageDialog(Main.getInstance().getMainFrame(), "Jawin ok"); } catch (Exception ex) { Errors.getInstance().showDetailedExceptionDialog(Main.getInstance().getMainFrame(), ex); } } }); res.put("Dev", dev); return res; }
From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java
public static void setBackgroundColor(Component cellRendererComponent, JTable tbl, Object oValue, boolean bSelected, boolean bHasFocus, int iRow, int iColumn) { cellRendererComponent.setBackground(bSelected ? tbl.getSelectionBackground() : iRow % 2 == 0 ? tbl.getBackground() : NuclosThemeSettings.BACKGROUND_PANEL); cellRendererComponent.setForeground(bSelected ? tbl.getSelectionForeground() : tbl.getForeground()); final TableModel tm; final int adjustColIndex; if (tbl instanceof FixedColumnRowHeader.HeaderTable && ((FixedColumnRowHeader.HeaderTable) tbl).getExternalTable() != null) { tm = ((FixedColumnRowHeader.HeaderTable) tbl).getExternalTable().getModel(); adjustColIndex = FixedRowIndicatorTableModel.ROWMARKERCOLUMN_COUNT; } else {//from w ww . j a v a 2s . co m tm = tbl.getModel(); adjustColIndex = 0; } // check whether the data of the component is readable for current user, by asking the security agent of the actual field if (tm instanceof SortableCollectableTableModel<?>) { final SortableCollectableTableModel<Collectable> tblModel = (SortableCollectableTableModel<Collectable>) tm; if (tblModel.getRowCount() > iRow) { final Collectable clct = tblModel.getCollectable(iRow); final Integer iTColumn = tbl.getColumnModel().getColumn(iColumn).getModelIndex() - adjustColIndex; final CollectableEntityField clctef = tblModel.getCollectableEntityField(iTColumn); if (clctef == null) { throw new NullPointerException("getTableCellRendererComponent failed to find field: " + clct + " tm index " + iTColumn); } boolean isEnabled = true; if (!clctef.isNullable() && isNull(oValue)) { cellRendererComponent.setBackground(getMandatoryColor()); cellRendererComponent.setForeground(tbl.getForeground()); } else { // if (clct.getId() == null) { // cellRendererComponent.setBackground(tbl.getBackground()); // cellRendererComponent.setForeground(tbl.getForeground()); // } else { if (tbl instanceof SubForm.SubFormTable) { SubFormTable subformtable = (SubForm.SubFormTable) tbl; Column subformcolumn = subformtable.getSubForm().getColumn(clctef.getName()); if (subformcolumn != null && !subformcolumn.isEnabled()) { isEnabled = false; if (bSelected) { cellRendererComponent .setBackground(NuclosThemeSettings.BACKGROUND_INACTIVESELECTEDCOLUMN); } else { cellRendererComponent.setBackground(NuclosThemeSettings.BACKGROUND_INACTIVECOLUMN); } } } // } try { EntityMetaDataVO meta = MetaDataClientProvider.getInstance() .getEntity(clctef.getEntityName()); if (meta.getRowColorScript() != null && !bSelected) { AbstractCollectableComponent.setBackground(cellRendererComponent, meta.getRowColorScript(), clct, meta, isEnabled); } } catch (CommonFatalException ex) { LOG.warn(ex); } } } } if (tbl instanceof TableRowMouseOverSupport) { TableRowMouseOverSupport trmos = (TableRowMouseOverSupport) tbl; if (trmos.isMouseOverRow(iRow)) { final Color bgColor = LangUtils.defaultIfNull(cellRendererComponent.getBackground(), Color.WHITE); cellRendererComponent .setBackground(new Color(Math.max(0, bgColor.getRed() - (bgColor.getRed() * 8 / 100)), Math.max(0, bgColor.getGreen() - (bgColor.getGreen() * 8 / 100)), Math.max(0, bgColor.getBlue() - (bgColor.getBlue() * 8 / 100)))); // cellRendererComponent.setBackground(UIManager.getColor("Table.selectionBackground")); } } }
From source file:org.o3project.optsdn.don.frame.NeFrame.java
/** * Create a pane that displays OMS connection information. * //from w ww .j a va2 s. c o m * @return The pane that displays OMS connection information */ private JScrollPane createOmsConnectionInfoPane() { Object[] header = OMS_CONNECTION_INFO_COLNAME_LIST.toArray(); String[][] rowDataList = new String[omsConnectionInfoList.size()][header.length]; for (int i = 0; i < rowDataList.length; i++) { List<Port> omsConnectionInfo = omsConnectionInfoList.get(i); Port port = omsConnectionInfo.get(0); int ofPortIndex = OMS_CONNECTION_INFO_COLNAME_LIST.indexOf(OmsConnectionInfoCols.OF_PORT.getName()); Integer openFlowPortId1 = port.getOpenFlowPortId(); String ofPortValue1; if (openFlowPortId1 == null) { ofPortValue1 = OFPORT_NOTFOUND; } else { ofPortValue1 = String.valueOf(openFlowPortId1); } rowDataList[i][ofPortIndex] = ofPortValue1; Port port2 = omsConnectionInfo.get(1); int connectedToIndex = OMS_CONNECTION_INFO_COLNAME_LIST .indexOf(OmsConnectionInfoCols.CONNECTED_TO.getName()); Integer openFlowPortId2 = port2.getOpenFlowPortId(); String ofPortValue2; if (openFlowPortId2 == null) { ofPortValue2 = OFPORT_NOTFOUND; } else { ofPortValue2 = String.valueOf(openFlowPortId2); } rowDataList[i][connectedToIndex] = port2.getNeId() + ", " + ofPortValue2; } JTable connectedTable = new JTable(rowDataList, header); connectedTable.getTableHeader().setBackground(Color.WHITE); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(SwingConstants.CENTER); for (int i = 0; i < header.length; i++) { TableColumn column = connectedTable.getColumnModel().getColumn(i); column.setCellRenderer(renderer); } JScrollPane connectedPane = new JScrollPane(); connectedPane.getViewport().setView(connectedTable); connectedPane.setPreferredSize(new Dimension(connectedPane.getPreferredSize().width, TABLE_HEIGHT)); return connectedPane; }
From source file:org.omegat.gui.align.AlignPanelController.java
private static void resizeRows(JTable table) { for (int row = 0; row < table.getRowCount(); row++) { int max = 0; for (int col = BeadTableModel.COL_SRC; col < table.getColumnCount(); col++) { int colWidth = table.getColumnModel().getColumn(col).getWidth(); TableCellRenderer cellRenderer = table.getCellRenderer(row, col); Component c = table.prepareRenderer(cellRenderer, row, col); c.setBounds(0, 0, colWidth, Integer.MAX_VALUE); int height = c.getPreferredSize().height; max = Math.max(max, height); }//from ww w .jav a 2 s . c o m table.setRowHeight(row, max); } }
From source file:org.openconcerto.erp.core.finance.accounting.element.AssociationCompteAnalytiqueSQLElement.java
public JTable creerJTable(ClasseCompte ccTmp) { final AssociationAnalytiqueModel model = new AssociationAnalytiqueModel(ccTmp); final JTable table = new JTable(model); final Vector vect = model.getRepartitionsAxe(); table.getColumnModel().getColumn(0).setCellRenderer(new PlanComptableCellRenderer(0)); table.getColumnModel().getColumn(1).setCellRenderer(new PlanComptableCellRenderer(0)); for (int i = 0; i < vect.size(); i++) { final Vector rep = (Vector) vect.get(i); JComboBox combo = new JComboBox(); for (int j = 0; j < rep.size(); j++) { combo.addItem(rep.get(j));//from w w w. ja va 2 s . c o m } table.getColumnModel().getColumn(i + 2).setCellEditor(new DefaultCellEditor(combo)); table.getColumnModel().getColumn(i + 2).setCellRenderer(new PlanComptableCellRenderer(0)); } table.getTableHeader().setReorderingAllowed(false); return table; }