List of usage examples for javax.swing JTable getRowCount
@BeanProperty(bound = false) public int getRowCount()
JTable
, given unlimited space. From source file:org.nuclos.client.ui.collect.CollectController.java
/** * command: delete current collectable in details<br> * Deletes the current collectable in Details mode. * * @deprecated Move to DetailsController and make private. *///from ww w .jav a 2 s. c om public void cmdDeleteCurrentCollectableInDetailsImpl() { try { // try to find next or previous object: final JTable tblResult = getResultTable(); final int iSelectedRow = tblResult.getSelectedRow(); if (iSelectedRow < 0) { throw new IllegalStateException(); } final int iNewSelectedRow; if (iSelectedRow < tblResult.getRowCount() - 1) { // the selected row is not the last row: select the next row iNewSelectedRow = iSelectedRow; } else if (iSelectedRow > 0) { // the selected row is not the first row: select the previous row iNewSelectedRow = iSelectedRow - 1; } else { // the selected row is the single row: don't select a row assert tblResult.getRowCount() == 1; assert iSelectedRow == 0; iNewSelectedRow = -1; } checkedDeleteSelectedCollectable(); getSearchStrategy().search(true); if (iNewSelectedRow == -1) { tblResult.getSelectionModel().clearSelection(); // switch to new mode: getResultController().getSearchResultStrategy().refreshResult(); } else { tblResult.getSelectionModel().setSelectionInterval(iNewSelectedRow, iNewSelectedRow); // go into view mode again: enterViewMode(); } } catch (CommonPermissionException ex) { final String sErrorMessage = getSpringLocaleDelegate().getMessage("GenericObjectCollectController.69", "Sie verf\u00fcgen nicht \u00fcber die ausreichenden Rechte, um diesen Datensatz zu l\u00f6schen."); Errors.getInstance().showExceptionDialog(getTab(), sErrorMessage, ex); } catch (CommonBusinessException ex) { if (!handleSpecialException(ex)) { Errors.getInstance().showExceptionDialog(getTab(), getSpringLocaleDelegate().getMessage("GenericObjectCollectController.31", "Der Datensatz konnte nicht gel\u00f6scht werden."), ex); } } }
From source file:org.nuclos.client.ui.collect.result.ResultController.java
/** * TODO: Make this package visible again. *//*from ww w . j a v a 2 s . c o m*/ public void setupResultPanel() { if (NuclosEntity.isNuclosEntity(getEntity().getName())) { this.getResultPanel().setActionsEnabled(false); } this.getResultPanel().addActionsVisibleListener(actionsVisibleListener); setupActions(); // add selection listener for Result table: final JTable tblResult = this.getResultPanel().getResultTable(); tblResult.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); tblResult.getSelectionModel().addListSelectionListener(newListSelectionListener(tblResult)); this.getResultPanel().btnToggleSelectionMode.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { getResultPanel().setToggleSelection(!getResultPanel().isToggleSelection()); } }); this.getResultPanel().btnSelectAllRows.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (tblResult.getRowCount() > 0) { tblResult.getSelectionModel().setSelectionInterval(0, tblResult.getRowCount() - 1); } } }); this.getResultPanel().btnDeSelectAllRows.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tblResult.getSelectionModel().clearSelection(); } }); this.getResultPanel().addResultKeyListener(new ResultKeyListener() { @Override public boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { if (e.getKeyCode() == ESC) { if (!pressed) { tblResult.getSelectionModel().clearSelection(); return true; } } else if (e.getKeyCode() == UP || e.getKeyCode() == DOWN) { if (pressed) { /* Warum wird dies bentigt? * BasicTableUI.actionPerformed(...) sendet ein ungewolltes changeSelection mit toggle=false bei PFEIL-NACH-OBEN/-UNTEN (siehe unten). * Der Standard in der Ergebnisansicht soll aber ein umgedrehtes Verhalten fr Mausklicks sein. (siehe Implementierung * ResultPanel: super.changeSelection(rowIndex, columnIndex, alternateSelectionToggle? !toggle: toggle, extend);) * * else if (!inSelection) { * moveWithinTableRange(table, dx, dy); * table.changeSelection(leadRow, leadColumn, false, extend); * } */ getResultPanel().setAlternateSelectionToggle(false); SwingUtilities.invokeLater(new Runnable() { public void run() { getResultPanel().setAlternateSelectionToggle(true); } }); } } return false; } }); // add mouse listener for double click in table: this.mouselistenerTableDblClick = new MouseAdapter() { private long lastClick = 0l; @Override public void mouseClicked(MouseEvent ev) { if (SwingUtilities.isLeftMouseButton(ev)) { if (lastClick + MainFrameTabbedPane.DOUBLE_CLICK_SPEED > System.currentTimeMillis()) { int iRow = tblResult.rowAtPoint(ev.getPoint()); if (iRow >= 0 && iRow < tblResult.getRowCount()) { tblResult.getSelectionModel().setSelectionInterval(iRow, iRow); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (getSelectedCollectableFromTableModel() != null) { clctctl.cmdViewSelectedCollectables(); } } }); } } lastClick = System.currentTimeMillis(); } } }; getResultPanel().addDoubleClickMouseListener(this.mouselistenerTableDblClick); if (!SecurityCache.getInstance() .isActionAllowed(Actions.ACTION_WORKSPACE_CUSTOMIZE_ENTITY_AND_SUBFORM_COLUMNS) && getMainFrame().getWorkspace().isAssigned()) { getResultPanel().getResultTable().getTableHeader().setReorderingAllowed(false); } // change column ordering in table model when table columns are reordered by dragging a column with the mouse: getResultPanel().addColumnModelListener(newColumnModelListener()); PreferencesUpdateListener pul = newResultTablePreferencesUpdateListener(); getResultPanel().addColumnModelListener(pul); getResultPanel().addPopupMenuListener(); getResultPanel().getSearchFilterBar().addEnabledListener(new ResetMainFilterEnabledListener()); getResultPanel().setActionsVisible( getCollectController().getPreferences().getBoolean(RESULT_ACTIONS_VISIBLE, true)); }
From source file:org.nuclos.client.ui.collect.result.ResultController.java
/** * @param tblResult//from w ww .j ava2 s . co m * @param bResultTruncated * @param iTotalNumberOfRecords * * TODO: Make package visible again. */ public void setStatusBar(JTable tblResult, boolean bResultTruncated, int iTotalNumberOfRecords) { String sStatus; if (iTotalNumberOfRecords == 0) { sStatus = getSpringLocaleDelegate().getMessage("ResultController.9", "Keinen zur Suchanfrage passenden Datensatz gefunden."); } else if (iTotalNumberOfRecords == 1) { sStatus = getSpringLocaleDelegate().getMessage("ResultController.2", "1 Datensatz gefunden."); } else { sStatus = getSpringLocaleDelegate().getMessage("ResultController.1", "{0} Datens\u00e4tze gefunden.", Integer.toString(iTotalNumberOfRecords)); if (bResultTruncated) { sStatus += getSpringLocaleDelegate().getMessage("ResultController.6", " Das Ergebnis wurde nach {0} Zeilen abgeschnitten.", tblResult.getRowCount()); } } this.getResultPanel().tfStatusBar.setText(sStatus); }
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 www. j a va 2 s . c o m*/ table.setRowHeight(row, max); } }
From source file:org.simmi.GeneSetHead.java
License:asdf
public Set<String> getSelspec(Component comp, final List<String> specs, final JCheckBox... contigs) { final JTable table = new JTable(); table.setDragEnabled(true);//w w w . j a va 2 s .co m JScrollPane scroll = new JScrollPane(table); table.setAutoCreateRowSorter(true); final List<Sequence> ctgs = new ArrayList<Sequence>(geneset.contigmap.values()); final TableModel contigmodel = new TableModel() { @Override public int getRowCount() { return ctgs.size(); } @Override public int getColumnCount() { return 1; } @Override public String getColumnName(int columnIndex) { return "Contigs/Scaffolds"; } @Override public Class<?> getColumnClass(int columnIndex) { return String.class; } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } @Override public Object getValueAt(int rowIndex, int columnIndex) { return ctgs.get(rowIndex).toString(); } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { } @Override public void addTableModelListener(TableModelListener l) { } @Override public void removeTableModelListener(TableModelListener l) { } }; final TableModel specmodel = new TableModel() { @Override public int getRowCount() { return specs.size(); } @Override public int getColumnCount() { return 2; } @Override public String getColumnName(int columnIndex) { return columnIndex == 0 ? "Id" : "Spec"; } @Override public Class<?> getColumnClass(int columnIndex) { return String.class; } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } @Override public Object getValueAt(int rowIndex, int columnIndex) { if (columnIndex == 1) return Sequence.nameFix(specs.get(rowIndex), true); else return specs.get(rowIndex); } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { } @Override public void addTableModelListener(TableModelListener l) { } @Override public void removeTableModelListener(TableModelListener l) { } }; table.setModel(specmodel); TransferHandler th = dragRows(table, specs); table.setTransferHandler(th); if (contigs != null && contigs.length > 0 && !contigs[0].getText().equals("Plasmid")) contigs[0].addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (contigs[0] != null && contigs[0].isSelected()) table.setModel(contigmodel); else table.setModel(specmodel); } }); Object[] ctls = new Object[] { scroll, contigs }; //Object[] ctls2 = new Object[] { scroll }; //if( contigs != null ) JOptionPane.showMessageDialog(comp, ctls); //else JOptionPane.showMessageDialog( comp, ctls2 ); Set<String> selspec = new LinkedHashSet<>(); for (int i = 0; i < table.getRowCount(); i++) { if (table.isRowSelected(i)) { String spec = (String) table.getValueAt(i, 0); System.err.println("test " + spec); selspec.add(spec); } } return selspec; }
From source file:org.simmi.GeneSetHead.java
License:asdf
public TransferHandler dragRows(final JTable table, final List<String> specs) { TransferHandler th = null;/* w ww .j av a2 s.co m*/ try { final DataFlavor ndf = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType); final DataFlavor df = DataFlavor.getTextPlainUnicodeFlavor(); final String charset = df.getParameter("charset"); final Transferable transferable = new Transferable() { @Override public Object getTransferData(DataFlavor arg0) throws UnsupportedFlavorException, IOException { if (arg0.equals(ndf)) { int[] rr = currentRowSelection; //table.getSelectedRows(); List<String> selseq = new ArrayList<String>(rr.length); for (int r : rr) { int i = table.convertRowIndexToModel(r); selseq.add(specs.get(i)); } return selseq; } else { String ret = "";//makeCopyString(); for (int r = 0; r < table.getRowCount(); r++) { Object o = table.getValueAt(r, 0); if (o != null) { ret += o.toString(); } else { ret += ""; } for (int c = 1; c < table.getColumnCount(); c++) { o = table.getValueAt(r, c); if (o != null) { ret += "\t" + o.toString(); } else { ret += "\t"; } } ret += "\n"; } //return arg0.getReaderForText( this ); return new ByteArrayInputStream(ret.getBytes(charset)); } //return ret; } @Override public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[] { df, ndf }; } @Override public boolean isDataFlavorSupported(DataFlavor arg0) { if (arg0.equals(df) || arg0.equals(ndf)) { return true; } return false; } }; th = new TransferHandler() { private static final long serialVersionUID = 1L; public int getSourceActions(JComponent c) { return TransferHandler.COPY_OR_MOVE; } public boolean canImport(TransferHandler.TransferSupport support) { return true; } protected Transferable createTransferable(JComponent c) { currentRowSelection = table.getSelectedRows(); return transferable; } public boolean importData(TransferHandler.TransferSupport support) { try { System.err.println(table.getSelectedRows().length); DataFlavor[] dfs = support.getDataFlavors(); if (support.isDataFlavorSupported(ndf)) { Object obj = support.getTransferable().getTransferData(ndf); ArrayList<String> seqs = (ArrayList<String>) obj; /*ArrayList<String> newlist = new ArrayList<String>( serifier.lgse.size() ); for( int r = 0; r < table.getRowCount(); r++ ) { int i = table.convertRowIndexToModel(r); newlist.add( specs.get(i) ); } serifier.lgseq.clear(); serifier.lgseq = newlist;*/ Point p = support.getDropLocation().getDropPoint(); int k = table.rowAtPoint(p); specs.removeAll(seqs); for (String s : seqs) { specs.add(k++, s); } TableRowSorter<TableModel> trs = (TableRowSorter<TableModel>) table.getRowSorter(); trs.setSortKeys(null); table.tableChanged(new TableModelEvent(table.getModel())); return true; } /* else if( support.isDataFlavorSupported( df ) ) { Object obj = support.getTransferable().getTransferData( df ); InputStream is = (InputStream)obj; System.err.println( charset ); importReader( new BufferedReader(new InputStreamReader(is, charset)) ); updateView(); return true; } else if( support.isDataFlavorSupported( DataFlavor.stringFlavor ) ) { Object obj = support.getTransferable().getTransferData( DataFlavor.stringFlavor ); String str = (String)obj; importReader( new BufferedReader( new StringReader(str) ) ); updateView(); return true; }*/ } catch (UnsupportedFlavorException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return false; } }; } catch (Exception e) { e.printStackTrace(); } return th; }
From source file:org.simmi.GeneSetHead.java
License:asdf
public void updateFilter(JTable table, RowFilter filter, Label label) { DefaultRowSorter<TableModel, Integer> rowsorter = (DefaultRowSorter<TableModel, Integer>) table .getRowSorter();/*from w ww .j a v a 2 s . c o m*/ rowsorter.setRowFilter(filter); if (label != null) label.setText(table.getRowCount() + "/" + table.getSelectedRowCount()); }
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 ww . j a v a2 s . co m columnModel.getColumn(column).setPreferredWidth(width); } }
From source file:org.tellervo.desktop.io.ImportDialog.java
@SuppressWarnings("unused") private static void updateRowHeights(JTable table) { try {/*from www . j a va 2s. co m*/ for (int row = 0; row < table.getRowCount(); row++) { int rowHeight = table.getRowHeight(); for (int column = 0; column < table.getColumnCount(); column++) { Component comp = table.prepareRenderer(table.getCellRenderer(row, column), row, column); rowHeight = Math.max(rowHeight, comp.getPreferredSize().height); } table.setRowHeight(row, rowHeight); } } catch (ClassCastException e) { } }
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. j ava 2 s . 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); } }