List of usage examples for javax.swing.table TableColumnModel getColumnCount
public int getColumnCount();
From source file:edu.ucla.stat.SOCR.chart.SuperHistogramChart.java
public void setXLabel(String xLabel) { domainLabel = xLabel;/* w ww .j a v a 2s . c o m*/ TableColumnModel columnModel = dataTable.getColumnModel(); for (int i = 0; i < columnModel.getColumnCount(); i += 2) columnModel.getColumn(i).setHeaderValue(xLabel); dataTable.setTableHeader(new EditableHeader(columnModel)); }
From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java
public void createDefaultColumnsFromModel(ArrayList fieldArray) { // Remove any current columns TableColumnModel cm = getColumnModel(); while (cm.getColumnCount() > 0) { cm.removeColumn(cm.getColumn(0)); }// w ww . j a va 2 s. c o m // Create new columns from the data model info int colCount = fieldArray.size(); for (int i = 0; i < colCount; i++) { TableColumn newColumn = new TableColumn(i); addColumn(newColumn); } // TableModel m = getModel(); // if (m != null) { // // Remove any current columns // 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++) { // TableColumn newColumn = new TableColumn(i); // addColumn(newColumn); // } // } }
From source file:com.diversityarrays.kdxplore.trials.TrialSelectionDialog.java
public TrialSelectionDialog(Window owner, String title, DALClient c, List<Trial> kdxTrials, Transformer<BackgroundRunner, TrialSearchOptionsPanel> searchOptionsPanelFactory) { super(owner, title, USE_TRIALS); setGlassPane(backgroundRunner.getBlockingPane()); searchOptionsPanel = searchOptionsPanelFactory.transform(backgroundRunner); helpInstructions = new JLabel(searchOptionsPanel.getHtmlHelp(GET_TRIALS)); kdxTrialByIdDownloaded = kdxTrials.stream().filter(t -> t.getIdDownloaded() != null) .collect(Collectors.toMap(Trial::getIdDownloaded, java.util.function.Function.identity())); trialRecordTable.setName(this.getClass().getName() + ".trialRecordTable"); //$NON-NLS-1$ TableColumnModel tcm = trialRecordTable.getColumnModel(); TableCellRenderer cellRenderer = new OptionalCheckboxRenderer("Already downloaded"); tcm.getColumn(trialRecordTableModel.getChosenColumnIndex()).setCellRenderer(cellRenderer); for (int col = tcm.getColumnCount(); --col >= 0;) { if ("TrialName".equals(trialRecordTable.getColumnName(col))) { TableColumn tc = tcm.getColumn(col); tc.setCellRenderer(new TrialNameCellRenderer()); break; }// ww w. j a v a2 s.co m } findTrialRecords.setEnabled(false); searchOptionsPanel.addSearchOptionsChangeListener(searchOptionsListener); wantTrialUnits.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { filteringClauseUsed = null; handleSearchOptionsChoiceChanged(); } }); setDALClient(c); initialiseGui(); if (owner != null) { Dimension ownerSize = owner.getSize(); Dimension mySize = getSize(); int w = (ownerSize.width * 3) / 4; int h = (ownerSize.height * 3) / 4; if (w > mySize.width || h > mySize.height) { if (w > mySize.width) { mySize.width = w; } if (h > mySize.height) { mySize.height = h; } setSize(mySize); } } // TODO consider using setSize to increase to parent's width getOkAction().setEnabled(false); trialRecordTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { getOkAction().setEnabled(trialRecordTableModel.getAnyChosen()); } }); }
From source file:SortableTable.java
/** * Changes the model for the table. Takes care of updating the header listener at the * same time.// w w w.j ava 2 s. c o m * * @param model the table model. * */ public void setSortableModel(final SortableTableModel model) { super.setModel(model); this.headerListener.setTableModel(model); final SortButtonRenderer renderer = new SortButtonRenderer(); final TableColumnModel cm = getColumnModel(); for (int i = 0; i < cm.getColumnCount(); i++) { cm.getColumn(i).setHeaderRenderer(renderer); } model.sortByColumn(0, true); }
From source file:SortableTable.java
/** * Standard constructor - builds a table for the specified model. * * @param model the data.//from ww w .j a v a 2s .c om */ public SortableTable(final SortableTableModel model) { super(model); final SortButtonRenderer renderer = new SortButtonRenderer(); final TableColumnModel cm = getColumnModel(); for (int i = 0; i < cm.getColumnCount(); i++) { cm.getColumn(i).setHeaderRenderer(renderer); } final JTableHeader header = getTableHeader(); this.headerListener = new SortableTableHeaderListener(model, renderer); header.addMouseListener(this.headerListener); header.addMouseMotionListener(this.headerListener); model.sortByColumn(0, true); }
From source file:userInterface.HospitalAdminRole.ManagePatientsJPanel.java
private void saveReportBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveReportBtnActionPerformed try {/*from w w w. j a v a 2s .c o m*/ HSSFWorkbook fWorkbook = new HSSFWorkbook(); HSSFSheet fSheet = fWorkbook.createSheet("new Sheet"); HSSFFont sheetTitleFont = fWorkbook.createFont(); File file = new File("C:\\Users\\Reshmi\\OneDrive\\Documents\\reports.xls"); HSSFCellStyle cellStyle = fWorkbook.createCellStyle(); sheetTitleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //sheetTitleFont.setColor(); TableModel model = vitalSignjTable.getModel(); TableColumnModel tcm = vitalSignjTable.getColumnModel(); HSSFRow fRow1 = fSheet.createRow((short) 0); for (int j = 0; j < tcm.getColumnCount(); j++) { HSSFCell cell = fRow1.createCell((short) j); cell.setCellValue(tcm.getColumn(j).getHeaderValue().toString()); } for (int i = 0; i < model.getRowCount(); i++) { HSSFRow fRow = fSheet.createRow((short) i + 1); for (int j = 0; j < model.getColumnCount(); j++) { HSSFCell cell = fRow.createCell((short) j); cell.setCellValue(tcm.getColumn(j).getHeaderValue().toString()); cell.setCellValue(model.getValueAt(i, j).toString()); cell.setCellStyle(cellStyle); } } FileOutputStream fileOutputStream; fileOutputStream = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream); fWorkbook.write(bos); bos.close(); fileOutputStream.close(); JOptionPane.showMessageDialog(null, "File saved as reports.xls ", "Export", JOptionPane.INFORMATION_MESSAGE); // Runtime run = Runtime.getRuntime(); // run.exec("cmd.exetart " + file); } catch (Exception e) { JOptionPane.showMessageDialog(null, "File not saved", "Export", JOptionPane.INFORMATION_MESSAGE); } }
From source file:it.iit.genomics.cru.igb.bundles.mi.view.MITable.java
public MITable(MITableModel model, IgbService service, final MIQuery query) { super(model); this.query = query; igbLogger = IGBLogger.getInstance(query.getLabel()); this.igbService = service; this.SymSelectionListener = new MouseListener() { @SuppressWarnings("unchecked") @Override//from ww w . j a va 2 s . co m public void mouseClicked(MouseEvent e) { if (e.getComponent().isEnabled() && e.getButton() == MouseEvent.BUTTON1) { if (getSelectedRow() >= 0) { int modelRow = convertRowIndexToModel(getSelectedRow()); MIResult interaction = ((MITableModel) getModel()).getResult(modelRow); structuresPanel.setCurrentInteraction(interaction); } MITable table = (MITable) e.getComponent(); int modelRow = convertRowIndexToModel(table.getSelectedRow()); int column = table.getSelectedColumn(); if (e.getClickCount() == 1) { if (column == MITableModel.TRACK_COLUMN) { Object value = table.getValueAt(table.getSelectedRow(), column); if (value instanceof JButton) { MIResult result = ((MITableModel) table.getModel()).getResult(modelRow); TypeContainerAnnot interactorTrack = result.createTrack(); igbService.addTrack(interactorTrack, interactorTrack.getID()); igbService.getSeqMapView().updatePanel(); for (TierGlyph t : igbService.getAllTierGlyphs()) { if (TierGlyph.TierType.ANNOTATION.equals(t.getTierType()) && (t.getAnnotStyle().getTrackName().equals(interactorTrack.getID()))) { SimpleTrackStyle style = new SimpleTrackStyle(interactorTrack.getID(), false) { @Override public boolean drawCollapseControl() { return false; } }; t.getAnnotStyle().copyPropertiesFrom(style); t.getAnnotStyle().setColorProvider(new RGB()); interactorTrack.setProperty(TrackLineParser.ITEM_RGB, "on"); } } igbService.getSeqMapView().updatePanel(); ((JButton) value).setText(interactorTrack.getID()); ((JButton) value).setEnabled(false); updateUI(); } } } else { // symmetry: zoom-in if (column == MITableModel.SYMS1_COLUMN) { MoleculeEntry entry = ((MITableModel) table.getModel()).getResult(modelRow) .getInteractor1(); if (query.getTaxid().equals(entry.getTaxid())) { Collection<SeqSymmetry> syms = ((MITableModel) table.getModel()).getResult(modelRow) .getSymmetries1(); zoomToSym(syms); } } else if (column == MITableModel.SYMS2_COLUMN) { MoleculeEntry entry = ((MITableModel) table.getModel()).getResult(modelRow) .getInteractor2(); if (query.getTaxid().equals(entry.getTaxid())) { Collection<SeqSymmetry> syms = ((MITableModel) table.getModel()).getResult(modelRow) .getSymmetries2(); zoomToSym(syms); } } // Protein: link to uniprot if (column == MITableModel.INTERACTOR1_COLUMN || column == MITableModel.INTERACTOR2_COLUMN) { MIResult miResult = ((MITableModel) table.getModel()).getResult(modelRow); String id; String taxid; MoleculeEntry interactor; if (column == MITableModel.INTERACTOR1_COLUMN) { interactor = miResult.getInteractor1(); } else { interactor = miResult.getInteractor2(); } taxid = interactor.getTaxid(); String query; String anchor = ""; switch (taxid) { case MoleculeEntry.TAXID_DNA: case MoleculeEntry.TAXID_RNA: if (miResult.getInteractionStructures().isEmpty()) { return; } query = "http://www.pdb.org/pdb/explore/explore.do?structureId=" + miResult.getInteractionStructures().iterator().next().getStructureID(); break; case MoleculeEntry.TAXID_LIGAND: if (miResult.getInteractionStructures().isEmpty()) { return; } query = DrugBankMapper.getInstance().isDrug(interactor.getGeneName()) ? DrugBankMapper.getInstance().getDrugBankLink(interactor.getGeneName()) : "http://www.ebi.ac.uk/pdbe-srv/pdbechem/chemicalCompound/show/" + interactor.getGeneName(); break; case MoleculeEntry.TAXID_MODIFICATION: query = "http://www.uniprot.org/uniprot/" + miResult.getInteractor1().getUniprotAc(); anchor = "#ptm_processing"; break; default: id = interactor.getUniprotAc(); query = "http://www.uniprot.org/uniprot/" + id; break; } try { URI uri = new URI(URIUtil.encodeQuery(query) + anchor); Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { desktop.browse(uri); } } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Cannot reach Uniprot website."); return; } catch (URISyntaxException ue) { JOptionPane.showMessageDialog(null, "Cannot reach Uniprot website: " + query); } } // interaction type: link to psicquic if (column == MITableModel.INTERACTION_TYPE_COLUMN) { MIResult miResult = ((MITableModel) table.getModel()).getResult(modelRow); String queryURL; String idA = miResult.getInteractor1().getUniprotAc(); String idB = miResult.getInteractor2().getUniprotAc(); if (null == miResult.getPsicquicUrl()) { // from the structure database if (query.searchDSysMap()) { queryURL = "http://http://dsysmap.irbbarcelona.org/results.php?type=proteins&neigh=2&value=" + idA + "," + idB; } else if (query.searchInteractome3D()) { try { queryURL = "http://interactome3d.irbbarcelona.org/interaction.php?ids=" + idA + ";" + idB + "&dataset=" + it.iit.genomics.cru.bridges.interactome3d.ws.Utils .getDataset(query.getTaxid()); } catch (Interactome3DException e3d) { // it will never happend: if the taxid was not known by // I3D, we wouldn't have an interaction return; } } else { return; } } else { if (false == idA.equals(idB)) { queryURL = miResult.getPsicquicUrl() + "query/id:" + miResult.getInteractor1().getUniprotAc() + "* AND id:" + miResult.getInteractor2().getUniprotAc() + "*"; } else { queryURL = miResult.getPsicquicUrl() + "query/idA:" + miResult.getInteractor1().getUniprotAc() + "* AND idB:" + miResult.getInteractor2().getUniprotAc() + "*"; } } try { URI uri = new URI(URIUtil.encodeQuery(queryURL)); Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { desktop.browse(uri); } } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Cannot reach psicquic server."); } catch (URISyntaxException ue) { JOptionPane.showMessageDialog(null, "Cannot reach psicquic server: " + queryURL); } } } } } @Override public void mousePressed(MouseEvent me) { } @Override public void mouseReleased(MouseEvent me) { } @Override public void mouseEntered(MouseEvent me) { } @Override public void mouseExited(MouseEvent me) { } }; TableRowSorter<MITableModel> sorter = new MITableRowSorter(model); setRowSorter(sorter); sorter.setRowFilter(evidenceRowFilter()); model.fireTableDataChanged(); this.getTableHeader().setReorderingAllowed(false); TableCellRenderer rend = getTableHeader().getDefaultRenderer(); TableColumnModel tcm = getColumnModel(); for (int j = 0; j < tcm.getColumnCount(); j += 1) { TableColumn tc = tcm.getColumn(j); TableCellRenderer rendCol = tc.getHeaderRenderer(); // likely null if (rendCol == null) { rendCol = rend; } Component c = rendCol.getTableCellRendererComponent(this, tc.getHeaderValue(), false, false, 0, j); tc.setPreferredWidth(c.getPreferredSize().width); } TableCellRenderer buttonRenderer = new JTableButtonRenderer(); getColumn(model.getColumnName(MITableModel.TRACK_COLUMN)).setCellRenderer(buttonRenderer); getColumn(model.getColumnName(MITableModel.SYMS1_COLUMN)).setCellRenderer(new GeneRenderer()); getColumn(model.getColumnName(MITableModel.SYMS2_COLUMN)).setCellRenderer(new GeneRenderer()); getColumn(model.getColumnName(MITableModel.INTERACTOR1_COLUMN)).setCellRenderer(new MoleculeRenderer()); getColumn(model.getColumnName(MITableModel.INTERACTOR2_COLUMN)).setCellRenderer(new MoleculeRenderer()); getColumn(model.getColumnName(MITableModel.INTERACTION_TYPE_COLUMN)) .setCellRenderer(new EvidenceRenderer()); getColumn(model.getColumnName(MITableModel.STRUCTURES_COLUMN)).setCellRenderer(new StructuresRenderer()); setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); int smallWidth = 75; int mediumWidth = 120; int largeWidth = 200; getColumnModel().getColumn(MITableModel.TRACK_COLUMN).setMinWidth(smallWidth); getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setMinWidth(smallWidth); getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setMaxWidth(smallWidth); getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setPreferredWidth(smallWidth); addMouseListener(SymSelectionListener); getSelectionModel().addListSelectionListener(new RowSelectionListener()); }
From source file:edu.ku.brc.specify.tasks.subpane.ESResultsTablePanel.java
/** * Constructor of a results "table" which is really a panel * @param esrPane the parent// w w w .j a v a2 s.c om * @param erTableInfo the info describing the results * @param installServices indicates whether services should be installed * @param isExpandedAtStartUp enough said * @param inclCloseBtn whether to include the close button on the bar */ public ESResultsTablePanel(final ExpressSearchResultsPaneIFace esrPane, final QueryForIdResultsIFace results, final boolean installServices, final boolean isExpandedAtStartUp, final boolean inclCloseBtn) { super(new BorderLayout()); this.esrPane = esrPane; this.results = results; this.bannerColor = results.getBannerColor(); this.isEditable = results.isEditingEnabled(); table = new JTable(); table.setShowVerticalLines(false); table.setRowSelectionAllowed(true); table.setSelectionMode(results.isMultipleSelection() ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION); setBackground(table.getBackground()); if (isEditable) { addContextMenu(); } topTitleBar = new GradiantLabel(results.getTitle(), SwingConstants.LEFT); topTitleBar.setBGBaseColor(bannerColor); topTitleBar.setTextColor(Color.WHITE); topTitleBar.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { expandBtn.doClick(); } } }); String description = results.getDescription(); if (StringUtils.isNotEmpty(description)) { topTitleBar.setToolTipText(description); } expandBtn = new TriangleButton(); expandBtn.setToolTipText(getResourceString("CollapseTBL")); expandBtn.setForeground(bannerColor); expandBtn.setTextColor(Color.WHITE); showTopNumEntriesBtn = new GradiantButton( String.format(getResourceString("ShowTopEntries"), new Object[] { topNumEntries })); showTopNumEntriesBtn.setForeground(bannerColor); showTopNumEntriesBtn.setTextColor(Color.WHITE); showTopNumEntriesBtn.setVisible(false); showTopNumEntriesBtn.setCursor(handCursor); List<ServiceInfo> services = installServices ? getServices() : null; //System.out.println("["+tableInfo.getTableId()+"]["+services.size()+"]"); StringBuffer colDef = new StringBuffer("p,0px,p:g,0px,p,0px,"); int numCols = (installServices ? services.size() : 0) + (inclCloseBtn ? 1 : 0); colDef.append(UIHelper.createDuplicateJGoodiesDef("p", "0px", numCols)); // add additional col defs for services PanelBuilder builder = new PanelBuilder(new FormLayout(colDef.toString(), "f:p:g")); CellConstraints cc = new CellConstraints(); int col = 1; builder.add(expandBtn, cc.xy(col, 1)); col += 2; builder.add(topTitleBar, cc.xy(col, 1)); col += 2; builder.add(showTopNumEntriesBtn, cc.xy(col, 1)); col += 2; if (installServices && services.size() > 0) { serviceBtns = new Hashtable<ServiceInfo, JButton>(); //IconManager.IconSize size = IconManager. int iconSize = AppPreferences.getLocalPrefs().getInt("banner.icon.size", 20); // Install the buttons on the banner with available services for (ServiceInfo serviceInfo : services) { GradiantButton btn = new GradiantButton(serviceInfo.getIcon(iconSize)); // XXX PREF btn.setToolTipText(serviceInfo.getTooltip()); btn.setForeground(bannerColor); builder.add(btn, cc.xy(col, 1)); ESTableAction esta = new ESTableAction(serviceInfo.getCommandAction(), table, serviceInfo.getTooltip()); esta.setProperty("gridtitle", results.getTitle()); btn.addActionListener(esta); serviceBtns.put(serviceInfo, btn); col += 2; } } GradiantButton closeBtn = null; if (inclCloseBtn) { closeBtn = new GradiantButton(IconManager.getIcon("Close")); closeBtn.setToolTipText(getResourceString("ESCloseTable")); closeBtn.setForeground(bannerColor); closeBtn.setRolloverEnabled(true); closeBtn.setRolloverIcon(IconManager.getIcon("CloseHover")); closeBtn.setPressedIcon(IconManager.getIcon("CloseHover")); builder.add(closeBtn, cc.xy(col, 1)); col += 2; } add(builder.getPanel(), BorderLayout.NORTH); tablePane = new JPanel(new BorderLayout()); setupTablePane(); if (isEditable) { //delRSItems = UIHelper.createI18NButton("RESTBL_DEL_ITEMS"); delRSItems = UIHelper.createIconBtn("DelRec", "ESDelRowsTT", null); delRSItems.addActionListener(createRemoveItemAL()); delRSItems.setEnabled(false); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { delRSItems.setEnabled(table.getSelectedRowCount() > 0); } } }); } add(tablePane, BorderLayout.CENTER); moveToRSCmd = new DragSelectedRowsBtn(IconManager.getIcon("Record_Set", IconManager.IconSize.Std16)); if (installServices) { PanelBuilder bottomBar = new PanelBuilder( new FormLayout("4px,p,4px,p,4px,p," + (delRSItems != null ? "4px,p," : "") + "f:p:g", "p")); bottomBar.add(moveToRSCmd, cc.xy(2, 1)); bottomBar.add(selectAllBtn, cc.xy(4, 1)); bottomBar.add(deselectAllBtn, cc.xy(6, 1)); if (delRSItems != null) { bottomBar.add(delRSItems, cc.xy(8, 1)); } botBtnPanel = bottomBar.getPanel(); deselectAllBtn.setEnabled(false); selectAllBtn.setEnabled(true); moveToRSCmd.setEnabled(true); deselectAllBtn.setToolTipText(getResourceString("SELALLTOOLTIP")); selectAllBtn.setToolTipText(getResourceString("DESELALLTOOLTIP")); moveToRSCmd.setToolTipText(getResourceString("MOVEROWSTOOLTIP")); selectAllBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { table.selectAll(); } }); deselectAllBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { table.clearSelection(); } }); moveToRSCmd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { RecordSetIFace src = (RecordSetIFace) moveToRSCmd.getData(); CommandDispatcher .dispatch(new CommandAction(RecordSetTask.RECORD_SET, "AskForNewRS", src, null, null)); } }); add(botBtnPanel, BorderLayout.SOUTH); } else { botBtnPanel = null; } expandBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { expandTable(false); } }); if (!isExpandedAtStartUp) { expandTable(true); } showTopNumEntriesBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { morePanel.setVisible(true); showTopNumEntriesBtn.setVisible(false); showingAllRows = false; setDisplayRows(rowCount, topNumEntries); // If it is collapsed then expand it if (!expandBtn.isDown()) { tablePane.setVisible(true); expandBtn.setDown(true); } // Make sure the layout is updated invalidate(); doLayout(); esrPane.revalidateScroll(); } }); if (closeBtn != null) { closeBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { removeMe(); } }); } }); } ResultSetTableModel rsm = createModel(); rsm.setPropertyListener(this); resultSetTableModel = rsm; table.setRowSorter(new TableRowSorter<ResultSetTableModel>(resultSetTableModel)); table.setRowSelectionAllowed(true); table.setModel(rsm); configColumns(); rowCount = rsm.getRowCount(); if (rowCount > topNumEntries + 2) { buildMorePanel(); setDisplayRows(rowCount, topNumEntries); } else { setDisplayRows(rowCount, Integer.MAX_VALUE); } invalidate(); doLayout(); UIRegistry.forceTopFrameRepaint(); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (botBtnPanel != null) { deselectAllBtn.setEnabled(table.getSelectedRowCount() > 0); selectAllBtn.setEnabled(table.getSelectedRowCount() != table.getRowCount()); moveToRSCmd.setEnabled(table.getSelectedRowCount() > 0); } } if (propChangeListener != null) { if (!e.getValueIsAdjusting()) { propChangeListener.propertyChange( new PropertyChangeEvent(this, "selection", table.getSelectedRowCount(), 0)); } else { propChangeListener.propertyChange( new PropertyChangeEvent(this, "selection", table.getSelectedRowCount(), 0)); } } } }); table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { //synchronized (((JTable)e.getSource()).getTreeLock()) //{ doDoubleClickOnRow(e); //} } }); // Horizontal Alignment is set later TableColumnModel tableColModel = table.getColumnModel(); for (int i = 0; i < tableColModel.getColumnCount(); i++) { tableColModel.getColumn(i).setCellRenderer(new BiColorTableCellRenderer()); } }
From source file:gov.noaa.ncdc.iosp.avhrr.util.AvhrrLevel1B2Netcdf.java
private void setTableCellRenderer(JTable table, TableCellRenderer renderer) { TableColumnModel columnModel = table.getColumnModel(); int columnCount = columnModel.getColumnCount(); for (int i = 0; i < columnCount; i++) { TableColumn column = columnModel.getColumn(i); if (i == 0) { column.setMaxWidth(90);//from ww w.j a v a 2s . c om } else { if (i > 1) { column.setMaxWidth(90); } if (i == (columnCount - 1)) { column.setMaxWidth(0); } if (i == (columnCount - 2)) { column.setMaxWidth(150); } column.setCellRenderer(renderer); } } }
From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java
/** * Creates default columns for the table from * the data model using the <code>getColumnCount</code> method * defined in the <code>TableModel</code> interface. * * Clears any existing columns before creating the * new columns based on information from the model. * * Overrides base class behaviour by setting the column width as a % of the * viewport width.//w ww.jav a2s.co m */ public void createDefaultColumnsFromModel() { TableModel m = getModel(); if (m != null) { // Remove any current columns TableColumnModel cm = getColumnModel(); while (cm.getColumnCount() > 0) { cm.removeColumn(cm.getColumn(0)); } // get parent width int parentWidth = 0; Component parent = getParent(); if (parent != null) { parentWidth = parent.getWidth(); } // Create new columns from the data model info int columnCount = m.getColumnCount(); for (int i = 0; i < m.getColumnCount(); i++) { int width = tableModel.getColumnWidth(i); if (width == 0) { width = parentWidth / columnCount; } else { //Width is a % of the viewport width width = (width * parentWidth) / 100; } TableColumn newColumn = new TableColumn(i); newColumn.setPreferredWidth(width); addColumn(newColumn); } } }