List of usage examples for javax.swing JTable getSelectedRow
@BeanProperty(bound = false) public int getSelectedRow()
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); if (table.getCellSelectionEnabled()) { table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); int rowIndex = table.getSelectedRow(); int colIndex = table.getSelectedColumn(); }/*from w w w .ja v a 2s . c om*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); if (table.getCellSelectionEnabled()) { table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); int rowIndexStart = table.getSelectedRow(); int rowIndexEnd = table.getSelectionModel().getMaxSelectionIndex(); int colIndexStart = table.getSelectedColumn(); int colIndexEnd = table.getColumnModel().getSelectionModel().getMaxSelectionIndex(); }/*from www . ja v a 2 s . co m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); if (table.getCellSelectionEnabled()) { // In the other modes, the set of selected cells can be retrieved using table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); // Get the min and max ranges of selected cells int rowIndexStart = table.getSelectedRow(); int rowIndexEnd = table.getSelectionModel().getMaxSelectionIndex(); int colIndexStart = table.getSelectedColumn(); int colIndexEnd = table.getColumnModel().getSelectionModel().getMaxSelectionIndex(); // Check each cell in the range for (int r = rowIndexStart; r <= rowIndexEnd; r++) { for (int c = colIndexStart; c <= colIndexEnd; c++) { if (table.isCellSelected(r, c)) { System.out.println("cell is selected"); }// w ww . ja va 2 s . com } } } }
From source file:it.unibas.spicygui.controllo.spicy.ActionShowSelectedTransformation.java
private void execute(Scenario scenario) { RankedTransformationsTopComponent topComponent = scenario.getRankedTransformationsTopComponent(); JTable tabellaRankedTransformations = topComponent.getTabellaRankedTransformations(); int selectedRow = tabellaRankedTransformations.getSelectedRow(); if (selectedRow != -1) { List<Transformation> rankedTransformations = (List<Transformation>) modello .getBean(Costanti.RANKED_TRANSFORMATIONS); Transformation selectedTransformation = rankedTransformations.get(selectedRow); modello.putBean(Costanti.SELECTED_TRANSFORMATION, selectedTransformation); SelectedTransformationTopComponent selectedTransformationTopComponent = scenario .getSelectedTransformationTopComponent(); selectedTransformationTopComponent.createTransformationOutput(); selectedTransformationTopComponent.openAtTabPosition(-1); selectedTransformationTopComponent.requestActive(); }/* www . jav a2s. com*/ }
From source file:it.unibas.spicygui.controllo.spicy.ActionShowSelectedMappingTask.java
private void execute(Scenario scenario) throws MissingResourceException { BestMappingsTopComponent topComponent = scenario.getBestMappingsTopComponent(); JTable tabellaBestMappings = topComponent.getTabellaBestMappings(); int selectedRow = tabellaBestMappings.getSelectedRow(); if (selectedRow != -1) { List<AnnotatedMappingTask> bestMappingTasks = (List<AnnotatedMappingTask>) modello .getBean(Costanti.BEST_MAPPING_TASKS); modello.putBean(Costanti.MAPPINGTASK_SELECTED, NbBundle.getMessage(Costanti.class, Costanti.TRANSFORMATION) + " n. " + selectedRow); AnnotatedMappingTask selectedAnnotatedMappingTask = bestMappingTasks.get(selectedRow); MappingTask mappingTask = scenario.getMappingTask(); mappingTask.setValueCorrespondences( selectedAnnotatedMappingTask.getMappingTask().getValueCorrespondences()); // MappingTaskInfo mappingTaskInfo = mappingTaskInfoCreator.createMappingTaskInfo(mappingTask); // modello.putBean(Costanti.MAPPINGTASK_INFO, mappingTaskInfo); // logger.info(mappingTaskInfo.toString()); List<SimilarityCheck> similarityChecks = (List<SimilarityCheck>) selectedAnnotatedMappingTask .getSimilarityChecks();//from w w w . jav a 2 s.c o m if (similarityChecks != null) { for (SimilarityCheck similarityCheck : similarityChecks) { logger.info(similarityCheck.toStringWithCircuits()); } } logger.info("OVERALL QUALITY: " + selectedAnnotatedMappingTask.getQualityMeasure()); TransformationTopComponent transformationTopComponent = scenario.getTransformationTopComponent(); transformationTopComponent.close(); InstancesTopComponent instancesTopComponent = scenario.getInstancesTopComponent(); instancesTopComponent.clearTranslated(); instancesTopComponent.close(); mappingTask.getTargetProxy().getIntermediateInstances().clear(); MappingTaskTopComponent mappingTaskTopComponent = scenario.getMappingTaskTopComponent(); mappingTaskTopComponent.drawConnections(); mappingTaskTopComponent.openAtTabPosition(-1); mappingTaskTopComponent.requestActive(); } }
From source file:fitmon.WorkoutLog.java
private void removeItem(java.awt.event.MouseEvent evt) { if (evt.getClickCount() == 1) { JTable target = (JTable) evt.getSource(); int row = target.getSelectedRow(); int column = target.getSelectedColumn(); String selectedwkt = (String) target.getValueAt(row, 0); //int index = selectedwkt.indexOf("--"); // String foodName = selectedFood.substring(0, index); //int calorie = selectedFood.substring(index+2); if (target.getColumnName(target.getSelectedColumn()).equals("Edit")) { DefaultTableModel model = (DefaultTableModel) tab.getModel(); model.removeRow(row);/*from ww w. j a va 2 s. c om*/ for (int i = 0; i < wkt.size(); i++) { if (wkt.get(i).getWorkout().equals(selectedwkt)) //&& wkt.get(i).getCal().equals(calorie)) { wkt.remove(i); break; } } } // do some action if appropriate column } // TODO add your handling code here: }
From source file:com.aw.swing.mvp.binding.component.BndSJTable.java
public static Object getSelectedRow(JTable jTable) { int selectedRowIndex = jTable.getSelectedRow(); return getRowAt(jTable, selectedRowIndex); }
From source file:fitmon.WorkoutLog.java
private void removeItem(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeItem if (evt.getClickCount() == 1) { JTable target = (JTable) evt.getSource(); int row = target.getSelectedRow(); int column = target.getSelectedColumn(); String selectedwkt = (String) target.getValueAt(row, 0); //int index = selectedwkt.indexOf("--"); // String foodName = selectedFood.substring(0, index); //int calorie = selectedFood.substring(index+2); if (target.getColumnName(target.getSelectedColumn()).equals("Edit")) { DefaultTableModel model = (DefaultTableModel) tab.getModel(); model.removeRow(row);//from www. j av a 2 s .co m for (int i = 0; i < wkt.size(); i++) { if (wkt.get(i).getWorkout().equals(selectedwkt)) //&& wkt.get(i).getCal().equals(calorie)) { wkt.remove(i); break; } } } // do some action if appropriate column } // TODO add your handling code here: }
From source file:SetValueAtToSetValue.java
public SetValueAtToSetValue() { final AbstractTableModel model = new MyModel(); final JTable table = new JTable(model); getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); model.setValueAt(new Integer(1), 0, 0); JButton button = new JButton("Increment selected cell"); getContentPane().add(button, BorderLayout.SOUTH); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int row = table.getSelectedRow(); int column = table.convertColumnIndexToModel(table.getSelectedColumn()); int currentValue = ((Integer) model.getValueAt(row, column)).intValue(); model.setValueAt(new Integer(currentValue + 1), row, column); }/*from w w w . j a v a 2 s . co m*/ }); pack(); }
From source file:Main.java
public Main() { final AbstractTableModel model = new MyModel(); final JTable table = new JTable(model); getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); model.setValueAt(new Integer(1), 0, 0); JButton button = new JButton("Increment selected cell"); getContentPane().add(button, BorderLayout.SOUTH); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int row = table.getSelectedRow(); int column = table.convertColumnIndexToModel(table.getSelectedColumn()); int currentValue = ((Integer) model.getValueAt(row, column)).intValue(); model.setValueAt(new Integer(currentValue + 1), row, column); }/*from w w w . jav a2 s. c o m*/ }); pack(); }