List of usage examples for javax.swing JTable setColumnSelectionAllowed
@BeanProperty(visualUpdate = true, description = "If true, an entire column is selected for each selected cell.") public void setColumnSelectionAllowed(boolean columnSelectionAllowed)
From source file:edu.ku.brc.specify.tasks.subpane.wb.DataImportDialog.java
/** * Parses the given import file according to the users selection and creates/updates the Preview table, * showing the user how the import options effect the way the data will be imported into the spreadsheet. * @param table - the table to display the data * @return/*from w ww . j ava 2 s .c om*/ * JTable - the table to display the data */ private JTable setCSVTableData(final JTable table) { try { log.debug("setTableData - file - " + configCSV.getFile().toString()); CsvReader csv = new CsvReader(new FileInputStream(configCSV.getFile()), configCSV.getDelimiter(), configCSV.getCharset()); csv.setEscapeMode(configCSV.getEscapeMode()); csv.setTextQualifier(configCSV.getTextQualifier()); String[] headers = {}; Vector<String[]> tableDataVector = new Vector<String[]>(); highestColumnCount = getLargestColumnCountFromCSV(); if (configCSV.getFirstRowHasHeaders()) { csv.readHeaders(); headers = csv.getHeaders(); } int rowColumnCount = 0; while (csv.readRecord()) { //how many columns does this row of data contain rowColumnCount = csv.getColumnCount(); //create an array that contains teh row data String[] rowData = new String[csv.getColumnCount()]; for (int col = 0; col < csv.getColumnCount(); col++) { rowData[col] = csv.get(col); } //if the column count in this row of data is not as large //as the column header count, then "insert" blank string into the cells String[] newArray = padArray(highestColumnCount, rowData, false); //stick the row data into a vector because we do not know how many //rows of data there are tableDataVector.add(newArray); } if (!configCSV.getFirstRowHasHeaders() || headers == null) { //create headers with names Column1, Column2... headers = createDummyHeaders(rowColumnCount); } //if the header count is not as large as the longest column count in the data set //create dummy headers and append to end of table. headers = padArray(highestColumnCount, headers, true); log.debug("---------------------------------------------------"); printArray(headers); log.debug("---------------------------------------------------"); //pull row data out of vector and stick into an array for table model. String[][] tableData = new String[tableDataVector.size()][rowColumnCount]; for (int i = 0; i < tableData.length; i++) { tableData[i] = tableDataVector.elementAt(i); printArray(tableData[i]); } if (checkForErrors(headers, tableData)) { errorPanel.showDataImportStatusPanel(true); } else { errorPanel.showDataImportStatusPanel(false); } if ((doesFirstRowHaveHeaders ? tableDataVector.size() - 1 : tableDataVector.size()) > WorkbenchTask.MAX_ROWS) { hasTooManyRows = true; showTooManyRowsErrorDialog(); } else { hasTooManyRows = false; } model = new PreviewTableModel(headers, tableData); table.setModel(model); table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(false); table.setCellSelectionEnabled(false); table.getTableHeader().setReorderingAllowed(false); table.setPreferredScrollableViewportSize(new Dimension(500, 100)); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setDefaultRenderer(String.class, new BiColorTableCellRenderer(false)); model.fireTableDataChanged(); model.fireTableStructureChanged(); return table; } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataImportDialog.class, ex); log.error("Error attempting to parse input csv file:" + ex); } return null; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
private void setJobQueueTableDefaults(JTable jobQueueTable, JobQueueTableModel jobQueueTableModel) { jobQueueTableModel.addTableModelListener(new JobQueueTableModelListener()); jobQueueTable.setModel(jobQueueTableModel); jobQueueTable.setSurrendersFocusOnKeystroke(true); jobQueueTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); jobQueueTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); jobQueueTable.setColumnSelectionAllowed(true); jobQueueTable.setRowSelectionAllowed(true); TableRenderer renderer = new TableRenderer(); TableColumn col = jobQueueTable.getColumnModel().getColumn(0); int width = 200; col.setPreferredWidth(width);/* w w w . ja v a2 s. c o m*/ col.setWidth(width); col.setCellRenderer(renderer); col = jobQueueTable.getColumnModel().getColumn(1); width = 1400; col.setPreferredWidth(width); col.setWidth(width); col.setCellRenderer(renderer); }
From source file:org.isatools.isacreator.gui.formelements.SubForm.java
protected void setTableProperties(JTable table, boolean isFieldName) { Font font = (!isFieldName) ? UIHelper.VER_12_PLAIN : UIHelper.VER_12_BOLD; table.setFont(font);//from w w w . ja v a2s . c om table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setColumnSelectionAllowed(true); table.setRowSelectionAllowed(true); table.setGridColor(UIHelper.LIGHT_GREEN_COLOR); table.setShowGrid(true); }
From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java
/** * Setup the JTable with its desired characteristics *///from w w w . j a va 2 s . c o m private void setupTable() { table = new CustomTable(spreadsheetModel); table.setShowGrid(true); table.setGridColor(Color.BLACK); table.setShowVerticalLines(true); table.setShowHorizontalLines(true); table.setGridColor(UIHelper.LIGHT_GREEN_COLOR); table.setRowSelectionAllowed(true); table.setColumnSelectionAllowed(true); table.setAutoCreateColumnsFromModel(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.getSelectionModel().addListSelectionListener(this); table.getColumnModel().getSelectionModel().addListSelectionListener(this); table.getTableHeader().setReorderingAllowed(true); table.getColumnModel().addColumnModelListener(this); try { table.setDefaultRenderer(Class.forName("java.lang.Object"), new SpreadsheetCellRenderer()); } catch (ClassNotFoundException e) { // ignore this error } table.addMouseListener(this); table.getTableHeader().addMouseMotionListener(new MouseMotionListener() { public void mouseDragged(MouseEvent event) { } public void mouseMoved(MouseEvent event) { // display a tooltip when user hovers over a column. tooltip is derived // from the description of a field from the TableReferenceObject. JTable table = ((JTableHeader) event.getSource()).getTable(); TableColumnModel colModel = table.getColumnModel(); int colIndex = colModel.getColumnIndexAtX(event.getX()); // greater than 1 to account for the row no. being the first col if (colIndex >= 1) { TableColumn tc = colModel.getColumn(colIndex); if (tc != null) { try { table.getTableHeader().setToolTipText(getFieldDescription(tc)); } catch (Exception e) { // ignore this error } } } } }); //table.getColumnModel().addColumnModelListener(this); InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0); // Override the default tab behaviour // Tab to the next editable cell. When no editable cells goto next cell. final Action previousTabAction = table.getActionMap().get(im.get(tab)); Action newTabAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { // maintain previous tab action procedure previousTabAction.actionPerformed(e); JTable table = (JTable) e.getSource(); int row = table.getSelectedRow(); int originalRow = row; int column = table.getSelectedColumn(); int originalColumn = column; while (!table.isCellEditable(row, column)) { previousTabAction.actionPerformed(e); row = table.getSelectedRow(); column = table.getSelectedColumn(); // Back to where we started, get out. if ((row == originalRow) && (column == originalColumn)) { break; } } if (table.editCellAt(row, column)) { table.getEditorComponent().requestFocusInWindow(); } } }; table.getActionMap().put(im.get(tab), newTabAction); TableColumnModel model = table.getColumnModel(); String previousColumnName = null; for (int columnIndex = 0; columnIndex < tableReferenceObject.getHeaders().size(); columnIndex++) { if (!model.getColumn(columnIndex).getHeaderValue().toString() .equals(TableReferenceObject.ROW_NO_TEXT)) { model.getColumn(columnIndex).setHeaderRenderer(columnRenderer); model.getColumn(columnIndex).setPreferredWidth(spreadsheetFunctions .calcColWidths(model.getColumn(columnIndex).getHeaderValue().toString())); // add appropriate cell editor for cell. spreadsheetFunctions.addCellEditor(model.getColumn(columnIndex), previousColumnName); previousColumnName = model.getColumn(columnIndex).getHeaderValue().toString(); } else { model.getColumn(columnIndex).setHeaderRenderer(new RowNumberCellRenderer()); } } JTableHeader header = table.getTableHeader(); header.setBackground(UIHelper.BG_COLOR); header.addMouseListener(new HeaderListener(header, columnRenderer)); table.addNotify(); }
From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java
/** * @return a specific table model with an overridden getValueAt method, providing access to subform entries. * * @deprecated Move to ResultController hierarchy. *//* ww w .ja va2 s . c o m*/ @Override protected SortableCollectableTableModel<CollectableGenericObjectWithDependants> newResultTableModel() { final SortableCollectableTableModel<CollectableGenericObjectWithDependants> result = new GenericObjectsResultTableModel<CollectableGenericObjectWithDependants>( getCollectableEntity(), getFields().getSelectedFields()); /** * @deprecated Move to ResultController hierarchy. */ class GenericObjectSortingRunnable implements CommonRunnable { @Override public void run() throws CommonBusinessException { final String baseEntity = getCollectableEntity().getName(); boolean canSort = true; for (SortKey sk : result.getSortKeys()) { final CollectableEntityField sortField = result.getCollectableEntityField(sk.getColumn()); if (!sortField.getEntityName().equals(baseEntity)) { if (sortField instanceof CollectableEOEntityField) { final CollectableEOEntityField f = (CollectableEOEntityField) sortField; if (f.getMeta().getPivotInfo() == null) { canSort = false; break; } } else { canSort = false; break; } } } if (canSort) { //NUCLEUSINT-1039 getResultController().getSearchResultStrategy().cmdSearch(); } else { result.setSortKeys(Collections.<SortKey>emptyList(), false); throw new CommonBusinessException( getSpringLocaleDelegate().getMessage("GenericObjectCollectController.19", "Das Suchergebnis kann nicht nach Unterformularspalten sortiert werden.")); } } } final JTable tbl = getResultTable(); // clicking header does not mean column selection, but sorting: tbl.setColumnSelectionAllowed(false); final GenericObjectSortingRunnable runnable = new GenericObjectSortingRunnable(); // clicking a column header is to cause a new search on the server: TableUtils.addMouseListenerForSortingToTableHeader(tbl, result, runnable); // @todo: this is not so nice a construct... maybe this should be moved to the result panel, because we use insight into the implementation of fixed tables here. TableUtils.addMouseListenerForSortingToTableHeader(getFixedResultTable(), result, runnable); return result; }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewer.java
private void setupTable() { tableModel = new ElementListTableModel(); table = new JXTable(tableModel); tableSorter = new ElementListTableSorter(tableModel, table); table.getTableHeader().addMouseListener(tableSorter); // add sorter & header renderer table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true);/* ww w .j ava 2s . c o m*/ // set our column widths ElementListTableModel.setupColumnWidths(table); table.setDefaultRenderer(Object.class, new ElementListCellRenderer(this, false)); table.setDefaultRenderer(Boolean.class, new BooleanCellRenderer(this, false)); // hide irrelevent columns TableColumnModelExt colmodel = (TableColumnModelExt) table.getColumnModel(); table.setColumnControlVisible(true); colmodel.getColumnExt(I18n.getText("hidden.MostRecentVersion")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.n")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.rec")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.hash")).setVisible(false); // popup menu table.addMouseListener(new PopupListener() { @Override public void showPopup(MouseEvent e) { // only clicks on tables if (!(e.getSource() instanceof JTable)) return; JTable table = (JTable) e.getSource(); ElementListTableModel model = (ElementListTableModel) table.getModel(); // get the row and sanity check int row = table.rowAtPoint(e.getPoint()); if (row < 0 || row >= model.getRowCount()) return; // select it? table.setRowSelectionInterval(row, row); // get the element Element element = model.getElementAt(row); // create and show the menu JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewer.this); popup.show(table, e.getX(), e.getY()); } }); }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewerOld.java
private void setupTable() { tableModel = new ElementListTableModel(); table = new JXTable(tableModel); tableSorter = new ElementListTableSorter(tableModel, table); table.getTableHeader().addMouseListener(tableSorter); // add sorter & header renderer table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true);/* ww w . jav a 2 s. c om*/ // set our column widths ElementListTableModel.setupColumnWidths(table); table.setDefaultRenderer(Object.class, new ElementListCellRenderer(this, false)); table.setDefaultRenderer(Boolean.class, new BooleanCellRenderer(this, false)); // hide irrelevent columns TableColumnModelExt colmodel = (TableColumnModelExt) table.getColumnModel(); table.setColumnControlVisible(true); colmodel.getColumnExt(I18n.getText("hidden.MostRecentVersion")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.n")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.rec")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.hash")).setVisible(false); // popup menu table.addMouseListener(new PopupListener() { @Override public void showPopup(MouseEvent e) { // only clicks on tables if (!(e.getSource() instanceof JTable)) return; JTable table = (JTable) e.getSource(); ElementListTableModel model = (ElementListTableModel) table.getModel(); // get the row and sanity check int row = table.rowAtPoint(e.getPoint()); if (row < 0 || row >= model.getRowCount()) return; // select it? table.setRowSelectionInterval(row, row); // get the element Element element = model.getElementAt(row); // create and show the menu JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewerOld.this); popup.show(table, e.getX(), e.getY()); } }); }