// This method from http://www.exampledepot.com/egs/javax.swing.table/PackCol.html public int packColumn(JTable table, int vColIndex, int margin) { DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel(); TableColumn col = colModel.getColumn(vColIndex); int width = 0; // Get width of column header TableCellRenderer renderer = col.getHeaderRenderer(); if (renderer == null) { renderer = table.getTableHeader().getDefaultRenderer(); } Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0); width = comp.getPreferredSize().width; // Get maximum width of column data for (int r = 0; r < table.getRowCount(); r++) { renderer = table.getCellRenderer(r, vColIndex); comp = renderer.getTableCellRendererComponent( table, table.getValueAt(r, vColIndex), false, false, r, vColIndex); width = Math.max(width, comp.getPreferredSize().width); } // Add margin width += 2 * margin; // Set the width col.setPreferredWidth(width); return width; }
/** Observer method to update the insuranceCompanyTable */ public void updateTable() { tableData.update( model.getInsuranceCompanies(), model.getSortingStrategy()); // Populate the table // Check if InsuranceCompany map is empty if (model.getInsuranceCompanies().size() > 0) { selectRow(); int selectedCompanyId = Integer.valueOf( (String) insuranceCompaniesTable.getValueAt(insuranceCompaniesTable.getSelectedRow(), 0)); controller.selectInsuranceCompany(selectedCompanyId); recordEdited = -1; // Reset the recordEdited field } else { // If all records are deleted, clear the edit panel companyIdTextField.setText(""); companyNameTextField.setText(""); urlTextField.setText(""); generalDescriptionTextField.setText(""); insuranceTypesTextField.setText(""); telephoneTextField.setText(""); percentageTextField.setText(""); } }
void okButton_actionPerformed(ActionEvent e) { int num_rows = filtersTable.getRowCount(); EditableDefinablePlugin edp = m_data.getPlugin(); for (int row = 0; row < num_rows; row++) { String mimeType = (String) filtersTable.getValueAt(row, 0); String mimeTypeValue = (String) filtersTable.getValueAt(row, 1); try { mimeTypeEditorBuilder.checkValue(edp, mimeType, mimeTypeValue); } catch (DynamicallyLoadedComponentException dlce) { String logMessage = "Failed to set the " + mimeTypeEditorBuilder.getValueName() + " for MIME type " + mimeType + " to " + mimeTypeValue; logger.error(logMessage, dlce); if (!EDPInspectorTableModel.handleDynamicallyLoadedComponentException(this, dlce)) { return; } else { logger.debug("User override; allow " + mimeTypeValue); } } } mimeTypeEditorBuilder.clear(edp); for (int row = 0; row < num_rows; row++) { String mimeType = (String) filtersTable.getValueAt(row, 0); String mimeTypeValue = (String) filtersTable.getValueAt(row, 1); try { mimeTypeEditorBuilder.put(edp, mimeType, mimeTypeValue); } catch (DynamicallyLoadedComponentException dlce) { String logMessage = "Internal error; MIME type " + mimeType + " not set to " + mimeTypeValue; logger.error(logMessage, dlce); } catch (PluginException.InvalidDefinition ex) { JOptionPane.showMessageDialog( this, ex.getMessage(), WordUtils.capitalize(mimeTypeEditorBuilder.getValueName()) + " Warning", JOptionPane.WARNING_MESSAGE); } } setVisible(false); }
// appointment time and what not public void mouseClicked(MouseEvent e) { int row = Cal.getSelectedRow(); // this will give you the row number int col = Cal.getSelectedColumn(); // this will give you the column number if (row != -1 && col != -1 && Cal.getValueAt(row, col) != null) { // this now will only activate when there is an actual date associated with // that day input(row, col, currentYear); } }
/** * Searches for InsuranceCompanies. Calls the controller and updates the tableData to the * searchMap. */ private void searchInsuranceCompany() { String query = searchTextField.getText(); controller.searchInsuranceCompanies(query); tableData.update( model.getSearchMap(), model.getSortingStrategy()); // Updates tableData and sortingStrategy // Enable automatic selection while searching if (tableData.getRowCount() > 0) { selectRow(); int selectedCompanyId = Integer.valueOf( (String) insuranceCompaniesTable.getValueAt(insuranceCompaniesTable.getSelectedRow(), 0)); controller.selectInsuranceCompany(selectedCompanyId); } }
/** Initial method to populate the insuranceCompaniesTable */ public void loadTable() { Map<Integer, InsuranceCompany> data = model.getInsuranceCompanies(); tableData = new InsuranceCompanyTableModel(data); insuranceCompaniesTable.setModel(tableData); insuranceCompaniesTable.getColumnModel().getColumn(0).setMaxWidth(50); insuranceCompaniesTable .getSelectionModel() .setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Check if db is empty and proceed with selecting only if the table is populated if (insuranceCompaniesTable.getRowCount() > 0) { // Set selected company according to selected row on load selectRow(); int selectedCompanyId = Integer.valueOf( (String) insuranceCompaniesTable.getValueAt(insuranceCompaniesTable.getSelectedRow(), 0)); } }
/** Observer method to update the editPanel and it's contents */ public void updateEditPanel() { InsuranceCompany insuranceCompany = model.getCurrentInsuranceCompany(); if (insuranceCompany != null) { // If no currentInsuranceCompany is set (if the db is empty) // Update all text fields String id = (String) insuranceCompaniesTable.getValueAt(insuranceCompaniesTable.getSelectedRow(), 0); companyIdTextField.setText(id); companyNameTextField.setText(insuranceCompany.getCompanyName()); urlTextField.setText(insuranceCompany.getUrl()); urlTextField.setCaretPosition(0); generalDescriptionTextField.setText(insuranceCompany.getGeneralDescription()); generalDescriptionTextField.setCaretPosition(0); insuranceTypesTextField.setText(insuranceCompany.getInsuranceTypes()); insuranceTypesTextField.setCaretPosition(0); telephoneTextField.setText(insuranceCompany.getTelephone()); percentageTextField.setText(Float.toString(insuranceCompany.getPercentage())); } }
private void doLaunch() throws IOException { // kicks off the launch after confirm and check if not null, two possibilities. Select Folder // sets flag and does folder. All others just makes a list. int reply = JOptionPane.showConfirmDialog( null, "Are you sure you want to launch?", "Launch?", JOptionPane.YES_NO_OPTION); if (reply == JOptionPane.YES_OPTION) { int numRow = table.getRowCount(); if (numRow < 1) { JOptionPane.showMessageDialog(frame, "You need to select tests to launch."); return; } if (selFoFl == 0) { try (BufferedWriter bw = new BufferedWriter( new FileWriter( "C:\\Projects\\testSeleniumFramework\\framework\\runSelectedTests.bat"))) { if (numRow < 2) { pullS = table.getValueAt(0, 0).toString(); } if (numRow > 1) { for (int i = 0; i < numRow; i++) { Object o = table.getValueAt(i, 0); pullS += ","; pullS += o.toString(); } } if (pullS.contains("null,")) { pullS = pullS.substring(5); } if (pullS.startsWith(",")) { pullS = pullS.substring(1); } // String lineC =""; if (flagF == 1) { lineC = "mvn clean test exec:java -Dconcordion.output.dir=\"" + placeS + "\" -Dexec.args=\"" + pullS + "\""; } if (flagF == 2) { lineC = "mvn clean test exec:java -Dconcordion.output.dir=\"" + placeS + "\" -Dexec.args=\"" + pullS + " Y\""; } if (flagF == 3) { lineC = "mvn clean test exec:java -Dconcordion.output.dir=\"" + placeS + "\" -Dexec.args=\"" + pullS + " ONLYFAIL\""; } bw.write( "Echo \"Launching tests..." + "\r\ncd C:\\Projects\\testSeleniumFramework\r\n" + lineC + "\r\n"); } pullS = ""; Process p = Runtime.getRuntime() .exec( "cmd /c start C:\\Projects\\testSeleniumFramework\\framework\\runSelectedTests.bat"); } if (selFoFl == 1) { try (BufferedWriter bw = new BufferedWriter( new FileWriter( "C:\\Projects\\testSeleniumFramework\\framework\\runSelectedTests.bat"))) { // String lineC = ""; if (flagF == 1) { lineC = "mvn clean test exec:java -Dconcordion.output.dir=\"" + placeS + "\" -Dexec.args=\"" + dtm.getValueAt(0, 1).toString() + "\\\""; } if (flagF == 2) { lineC = "mvn clean test exec:java -Dconcordion.output.dir=\"" + placeS + "\" -Dexec.args=\"" + dtm.getValueAt(0, 1).toString() + "\\ Y\""; } if (flagF == 3) { lineC = "mvn clean test exec:java -Dconcordion.output.dir=\"" + placeS + "\" -Dexec.args=\"" + dtm.getValueAt(0, 1).toString() + "\\ ONLYFAIL\""; } bw.write( "Echo \"Launching tests..." + "\r\ncd C:\\Projects\\testSeleniumFramework\r\n" + lineC + "\r\n"); } pullS = ""; Process p = Runtime.getRuntime() .exec( "cmd /c start C:\\Projects\\testSeleniumFramework\\framework\\runSelectedTests.bat"); } } else { } }
public ArrayList getSelectedMessages() { ArrayList list = new ArrayList(); for (int i = 0; i < table.getRowCount(); i++) { if (((Boolean) table.getValueAt(i, 0)) == true) { list.add(msgID[i]); } } return list; }