List of usage examples for javax.swing JTable getSelectedColumns
@BeanProperty(bound = false) public int[] getSelectedColumns()
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); if (table.getColumnSelectionAllowed() && !table.getRowSelectionAllowed()) { int[] vColIndices = table.getSelectedColumns(); }//from w w w .j a va2 s .c o m }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTable table; String[] columnTitles = { "A", "B", "C", "D" }; Object[][] rowData = { { "11", "12", "13", "14" }, { "21", "22", "23", "24" }, { "31", "32", "33", "34" }, { "41", "42", "44", "44" } }; table = new JTable(rowData, columnTitles); table.setCellSelectionEnabled(true); ListSelectionModel cellSelectionModel = table.getSelectionModel(); cellSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); cellSelectionModel.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { String selectedData = null; int[] selectedRow = table.getSelectedRows(); int[] selectedColumns = table.getSelectedColumns(); for (int i = 0; i < selectedRow.length; i++) { for (int j = 0; j < selectedColumns.length; j++) { selectedData = (String) table.getValueAt(selectedRow[i], selectedColumns[j]); }//from w w w . j ava 2 s . co m } System.out.println("Selected: " + selectedData); } }); frame.add(new JScrollPane(table)); frame.setSize(300, 200); frame.setVisible(true); }
From source file:com.vgi.mafscaling.MafCompare.java
public MafCompare() { compExcelAdapter = new ExcelAdapter() { //@override protected void onPaste(JTable table, boolean extendRows, boolean extendCols) { super.onPaste(table, extendRows, extendCols); int colCount = compMafTable.getColumnCount(); Utils.ensureColumnCount(colCount, origMafTable); Utils.ensureColumnCount(colCount, newMafTable); ArrayList<Object> values = new ArrayList<Object>(); int i; for (i = (table.getSelectedColumns())[0]; i < colCount; ++i) values.add(compMafTable.getValueAt(0, i)); double corr; int j = 0; for (i = (table.getSelectedColumns())[0]; i < colCount; ++i, ++j) { if (Pattern.matches(Utils.fpRegex, values.get(j).toString()) && Pattern.matches(Utils.fpRegex, origMafTable.getValueAt(1, i).toString())) { corr = Double.valueOf(values.get(j).toString()) / 100.0 + 1.0; newMafTable.setValueAt(Double.valueOf(origMafTable.getValueAt(1, i).toString()) * corr, 1, i);/*from w w w . j a v a 2s . c o m*/ } else break; } } }; initialize(); }
From source file:net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.GenericWikiTableTransformer.java
/** * @see/*from w w w . jav a2 s . com*/ * net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.IWikiTableTransformer * #transform(javax.swing.JTable) */ @Override public String transform(JTable table) { int nbrSelRows = table.getSelectedRowCount(); int nbrSelCols = table.getSelectedColumnCount(); int[] selRows = table.getSelectedRows(); int[] selCols = table.getSelectedColumns(); if (selRows.length != 0 && selCols.length != 0) { StringBuilder buf = new StringBuilder(1024); // Start the table appendWithReplacement(buf, configuration.getTableStartTag()); // Create the header appendWithReplacement(buf, configuration.getHeaderStartTag()); for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx) { appendWithReplacement(buf, configuration.getHeaderCell(), table.getColumnName(selCols[colIdx])); } appendWithReplacement(buf, configuration.getHeaderEndTag()); // Now fill all the table rows for (int rowIdx = 0; rowIdx < nbrSelRows; ++rowIdx) { appendWithReplacement(buf, configuration.getRowStartTag()); for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx) { TableCellRenderer cellRenderer = table.getCellRenderer(selRows[rowIdx], selCols[colIdx]); Object cellObj = table.getValueAt(selRows[rowIdx], selCols[colIdx]); if (cellRenderer instanceof SquirrelTableCellRenderer) { cellObj = ((SquirrelTableCellRenderer) cellRenderer).renderValue(cellObj); } String value = null; if (cellObj == null) { value = ""; //$NON-NLS-1$ } else { final String tmp = cellObj.toString(); if (tmp.trim().equals("")) { //$NON-NLS-1$ value = ""; //$NON-NLS-1$ } else { value = tmp; } } appendWithReplacement(buf, configuration.getDataCell(), value); } appendWithReplacement(buf, configuration.getRowEndTag()); } appendWithReplacement(buf, configuration.getTableEndTag()); return buf.toString(); } else { return null; } }