List of usage examples for javax.swing.table TableModel getValueAt
public Object getValueAt(int rowIndex, int columnIndex);
columnIndex
and rowIndex
. From source file:com.qspin.qtaste.ui.xmleditor.TestRequirementEditor.java
private void computeColumnWidths() { // horizontal spacing int hspace = 6; TableModel model = m_TestRequirementTable.getModel(); // rows no// ww w.j a va2 s. c o m int cols = model.getColumnCount(); // columns no int rows = model.getRowCount(); // width vector int w[] = new int[model.getColumnCount()]; // computes headers widths for (int i = 0; i < cols; i++) { w[i] = (int) m_TestRequirementTable .getDefaultRenderer(String.class).getTableCellRendererComponent(m_TestRequirementTable, m_TestRequirementModel.getColumnName(i), false, false, -1, i) .getPreferredSize().getWidth() + hspace; TableColumn hcol = m_TestRequirementTable.getColumn(m_TestRequirementModel.getColumnName(i)); hcol.setHeaderRenderer(new MyTableHeaderRenderer()); } // check if cell values fit in their cells and if not // keep in w[i] the necessary with for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { Object o = model.getValueAt(i, j); int width = 0; if (o != null) { width = (int) m_TestRequirementTable.getCellRenderer(i, j) .getTableCellRendererComponent(m_TestRequirementTable, o, false, false, i, j) .getPreferredSize().getWidth() + hspace; } if (w[j] < width) { w[j] = width; } } } TableColumnModel colModel = m_TestRequirementTable.getColumnModel(); // and finally setting the column widths for (int i = 0; i < cols; i++) { colModel.getColumn(i).setPreferredWidth(w[i]); } }
From source file:fll.web.FullTournamentTest.java
/** * Simulate entering subjective scores by pulling them out of testDataConn. * /*from w w w.j a va 2 s. co m*/ * @param testDataConn Where to get the test data from * @param challengeDocument the challenge descriptor * @throws SQLException * @throws SAXException * @throws InterruptedException */ private void enterSubjectiveScores(final Connection testDataConn, final ChallengeDescription description, final Tournament sourceTournament, final Path outputDirectory) throws SQLException, IOException, MalformedURLException, ParseException, SAXException, InterruptedException { final Path subjectiveZip = outputDirectory .resolve(sanitizeFilename(sourceTournament.getName()) + "_subjective-data.fll"); IntegrationTestUtils.downloadFile(new URL(TestUtils.URL_ROOT + "admin/subjective-data.fll"), "application/zip", subjectiveZip); final SubjectiveFrame subjective = new SubjectiveFrame(); subjective.load(subjectiveZip.toFile()); // insert scores into zip for (final ScoreCategory subjectiveElement : description.getSubjectiveCategories()) { final String category = subjectiveElement.getName(); final String title = subjectiveElement.getTitle(); // find appropriate table model final TableModel tableModel = subjective.getTableModelForTitle(title); Assert.assertNotNull(tableModel); final int teamNumberColumn = findColumnByName(tableModel, "TeamNumber"); Assert.assertTrue("Can't find TeamNumber column in subjective table model", teamNumberColumn >= 0); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Found team number column at " + teamNumberColumn); } try (final PreparedStatement prep = testDataConn .prepareStatement("SELECT * FROM " + category + " WHERE Tournament = ?")) { prep.setInt(1, sourceTournament.getTournamentID()); try (final ResultSet rs = prep.executeQuery()) { while (rs.next()) { final int teamNumber = rs.getInt("TeamNumber"); // find row number in table int rowIndex = -1; for (int rowIdx = 0; rowIdx < tableModel.getRowCount(); ++rowIdx) { final Object teamNumberRaw = tableModel.getValueAt(rowIdx, teamNumberColumn); Assert.assertNotNull(teamNumberRaw); final int value = Utilities.NUMBER_FORMAT_INSTANCE.parse(teamNumberRaw.toString()) .intValue(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Checking if " + teamNumber + " equals " + value + " raw: " + teamNumberRaw + "? " + (value == teamNumber) + " rowIdx: " + rowIdx + " numRows: " + tableModel.getRowCount()); } if (value == teamNumber) { rowIndex = rowIdx; break; } } Assert.assertTrue("Can't find team " + teamNumber + " in subjective table model", rowIndex >= 0); if (rs.getBoolean("NoShow")) { // find column for no show final int columnIndex = findColumnByName(tableModel, "No Show"); Assert.assertTrue("Can't find No Show column in subjective table model", columnIndex >= 0); tableModel.setValueAt(Boolean.TRUE, rowIndex, columnIndex); } else { for (final AbstractGoal goalElement : subjectiveElement.getGoals()) { if (!goalElement.isComputed()) { final String goalName = goalElement.getName(); final String goalTitle = goalElement.getTitle(); // find column index for goal and call set final int columnIndex = findColumnByName(tableModel, goalTitle); Assert.assertTrue( "Can't find " + goalTitle + " column in subjective table model", columnIndex >= 0); final int value = rs.getInt(goalName); tableModel.setValueAt(Integer.valueOf(value), rowIndex, columnIndex); } } } // not NoShow } // foreach score } // try ResultSet } // try PreparedStatement } // foreach category subjective.save(); // upload scores IntegrationTestUtils.loadPage(selenium, TestUtils.URL_ROOT + "admin/index.jsp"); final WebElement fileInput = selenium.findElement(By.name("subjectiveFile")); fileInput.sendKeys(subjectiveZip.toAbsolutePath().toString()); selenium.findElement(By.id("uploadSubjectiveFile")).click(); Assert.assertFalse(IntegrationTestUtils.isElementPresent(selenium, By.id("error"))); Assert.assertTrue(IntegrationTestUtils.isElementPresent(selenium, By.id("success"))); }
From source file:edu.ku.brc.specify.config.init.PrintTableHelper.java
/** * @param model//from ww w . j a v a 2 s.c o m * @return * @throws Exception */ public DynamicReport buildReport(final TableModel model, final PageSetupDlg pageSetupDlg) throws Exception { // Find a Sans Serif Font on the System String fontName = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (java.awt.Font font : ge.getAllFonts()) { String fName = font.getFamily().toLowerCase(); if (StringUtils.contains(fName, "sansserif") || StringUtils.contains(fName, "arial") || StringUtils.contains(fName, "verdana")) { fontName = font.getFamily(); break; } } if (fontName == null) { fontName = Font._FONT_TIMES_NEW_ROMAN; } /** * Creates the DynamicReportBuilder and sets the basic options for the report */ FastReportBuilder drb = new FastReportBuilder(); Style columDetail = new Style(); //columDetail.setBorder(Border.THIN); Style columDetailWhite = new Style(); //columDetailWhite.setBorder(Border.THIN); columDetailWhite.setBackgroundColor(Color.WHITE); columDetailWhite.setFont(new Font(10, fontName, false)); columDetailWhite.setHorizontalAlign(HorizontalAlign.CENTER); columDetailWhite.setBlankWhenNull(true); Style columDetailWhiteBold = new Style(); //columDetailWhiteBold.setBorder(Border.THIN); columDetailWhiteBold.setBackgroundColor(Color.WHITE); Style titleStyle = new Style(); titleStyle.setFont(new Font(12, fontName, true)); // Odd Row Style Style oddRowStyle = new Style(); //oddRowStyle.setBorder(Border.NO_BORDER); oddRowStyle.setHorizontalAlign(HorizontalAlign.CENTER); Color veryLightGrey = new Color(240, 240, 240); oddRowStyle.setBackgroundColor(veryLightGrey); oddRowStyle.setTransparency(Transparency.OPAQUE); // Create Column Headers for the Report for (int i = 0; i < model.getColumnCount(); i++) { String colName = model.getColumnName(i); Class<?> dataClass = model.getColumnClass(i); if (dataClass == Object.class) { if (model.getRowCount() > 0) { Object data = model.getValueAt(0, i); if (data != null) { dataClass = data.getClass(); } else { // Column in first row was null so search down the rows // for a non-empty cell for (int j = 1; j < model.getRowCount(); j++) { data = model.getValueAt(j, i); if (dataClass != null) { dataClass = data.getClass(); break; } } if (dataClass == null) { dataClass = String.class; } } } } ColumnBuilder colBldr = ColumnBuilder.getInstance().setColumnProperty(colName, dataClass.getName()); int bracketInx = colName.indexOf('['); if (bracketInx > -1) { colName = colName.substring(0, bracketInx - 1); } colBldr.setTitle(colName); colBldr.setStyle(columDetailWhite); AbstractColumn column = colBldr.build(); drb.addColumn(column); Style headerStyle = new Style(); headerStyle.setFont(new Font(11, fontName, true)); //headerStyle.setBorder(Border.THIN); headerStyle.setHorizontalAlign(HorizontalAlign.CENTER); headerStyle.setVerticalAlign(VerticalAlign.MIDDLE); headerStyle.setBackgroundColor(new Color(80, 80, 80)); headerStyle.setTransparency(Transparency.OPAQUE); headerStyle.setTextColor(new Color(255, 255, 255)); column.setHeaderStyle(headerStyle); } drb.setTitle(pageSetupDlg.getPageTitle()); drb.setTitleStyle(titleStyle); drb.setLeftMargin(20); drb.setRightMargin(20); drb.setTopMargin(10); drb.setBottomMargin(10); drb.setPrintBackgroundOnOddRows(true); drb.setOddRowBackgroundStyle(oddRowStyle); drb.setColumnsPerPage(new Integer(1)); drb.setUseFullPageWidth(true); drb.setColumnSpace(new Integer(5)); // This next line causes an exception // Event with DynamicReport 3.0.12 and JasperReposrts 3.7.3 //drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_FOOTER, AutoText.ALIGMENT_CENTER); Page[] pageSizes = new Page[] { Page.Page_Letter_Portrait(), Page.Page_Legal_Portrait(), Page.Page_A4_Portrait(), Page.Page_Letter_Landscape(), Page.Page_Legal_Landscape(), Page.Page_A4_Landscape() }; int pageSizeInx = pageSetupDlg.getPageSize() + (pageSetupDlg.isPortrait() ? 0 : 3); drb.setPageSizeAndOrientation(pageSizes[pageSizeInx]); DynamicReport dr = drb.build(); return dr; }
From source file:com.osparking.attendant.AttListForm.java
private void managerCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_managerCheckBoxActionPerformed TableModel attModel = usersTable.getModel(); String adminAuthority = attModel.getValueAt(usersTable.getSelectedRow(), 2).toString(); boolean wasManager = adminAuthority.equals("Y"); if (formMode == CreateMode && managerCheckBox.isSelected()) { changeSaveButtonEnabled(managerCheckBox, false); } else {// w w w . jav a 2 s. c om if (managerCheckBox.isSelected() && wasManager || !managerCheckBox.isSelected() && !wasManager) { changeSaveButtonEnabled(managerCheckBox, true); } else if (managerCheckBox.isSelected() && !wasManager || !managerCheckBox.isSelected() && wasManager) { changeSaveButtonEnabled(managerCheckBox, false); } } }
From source file:com.osparking.attendant.AttListForm.java
private void changeFieldButtonUsability(int clickedRow) { TableModel attModel = usersTable.getModel(); String rowID = attModel.getValueAt(clickedRow, 0).toString(); boolean rowForManager = (attModel.getValueAt(clickedRow, 2).toString().equals("Y") ? true : false); if (loginID == null) { return;/*from w w w . j a va 2 s . c o m*/ } if (rowID.equals(loginID)) { // Login user self information is under consideration. deleteButton.setEnabled(false); changeUserPasswordEnabled(false); changeTextFieldEnabled(true); multiFuncButton.setEnabled(true); } else if (loginID.equals(ADMIN_ID) || // non-admin is handled row by admin isManager && !rowForManager) // non-manager is handled row by manager { deleteButton.setEnabled(true); changeUserPasswordEnabled(true); changeTextFieldEnabled(true); multiFuncButton.setEnabled(true); } else { disableModifiability(); } // Attendant is created by who? if (isManager) { createButton.setEnabled(true); } else { createButton.setEnabled(false); managerCBoxEnabled(false); } }
From source file:com.osparking.attendant.AttListForm.java
/** * Checks E-mail address whenever its content is modified. * Even after an E-mail is once verified to be good, for each typing, e-mail check button needs to be * considered to be enabled.//from w ww. j a va 2s . c om * @param evt event */ private void EmailTypedHandler(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_EmailTypedHandler java.awt.EventQueue.invokeLater(new Runnable() { public void run() { String tempEmail = emailAddrText.getText().trim(); if (tempEmail.length() == 0) { // when e-mail address isn't entered, check button is to be disabled Email_usable = true; checkEmailButton.setEnabled(false); } else { if (formMode == CreateMode) { checkEmailButton.setEnabled(true); } else { TableModel attModel = usersTable.getModel(); int row = usersTable.getSelectedRow(); String oriEmail = attModel.getValueAt(row, 5).toString(); if (tempEmail.equals(oriEmail)) { checkEmailButton.setEnabled(false); } else { checkEmailButton.setEnabled(true); } } } } }); }
From source file:com.osparking.attendant.AttListForm.java
private void showAttendantDetail(int clickedRow) { TableModel attModel = usersTable.getModel(); if (attModel.getRowCount() == 0) { // Clear attendant detail panel as no one is selected currently. return;/*from w ww .j a v a2 s . c o m*/ } Object field = null; if (formMode != FormMode.CreateMode) { // <editor-fold defaultstate="collapsed" desc="-- Display ID and E-mail, initialize password"> userIDText.setText(attModel.getValueAt(clickedRow, 0).toString()); changeFieldButtonUsability(clickedRow); field = attModel.getValueAt(clickedRow, 5); if (field == null) { emailAddrText.setText(""); } else { emailAddrText.setText(field.toString()); emailAddrText.setCaretPosition(0); } changePWCheckBox.setSelected(false); ChangeNewPasswordEnabled(false); userPassword.setText(""); creationDateText.setText(attModel.getValueAt(clickedRow, 6).toString()); // </editor-fold> } userNameText.setText(attModel.getValueAt(clickedRow, 1).toString()); String adminAuthority = attModel.getValueAt(clickedRow, 2).toString(); managerCheckBox.setSelected(adminAuthority.equals("Y")); // <editor-fold defaultstate="collapsed" desc="-- 2 Display or copy phone number"> field = attModel.getValueAt(clickedRow, 3); if (field == null) { cellPhoneText.setText(""); } else { cellPhoneText.setText(field.toString()); } field = attModel.getValueAt(clickedRow, 4); if (field == null) { phoneText.setText(""); } else { phoneText.setText(field.toString()); } // </editor-fold> if (isManager) { userPassword.setToolTipText(PW_INPUT_TOOTLTIP.getContent()); userPWLabel.setToolTipText((PW_INPUT_TOOTLTIP.getContent())); } }
From source file:semaforo.Semaforo.java
private int getFilaTickerFrontEnd(TableModel temp, String name) { int i = 0;/* w ww . j a v a 2s. com*/ String tickerName = ""; Object objTicker = null; while (i < temp.getRowCount()) { objTicker = temp.getValueAt(i, 0); if (objTicker != null) { tickerName = objTicker.toString(); if (tickerName.compareTo(name) == 0) { break; } } i++; } return (i == temp.getRowCount()) ? -1 : i; }
From source file:edu.ku.brc.ui.UIHelper.java
/** * Calculates and sets the each column to it preferred size. NOTE: This * method also sets the table height to 10 rows. * /* w w w.j a v a2s .c om*/ * @param table the table to fix up * @param numRowsHeight the number of rows to make the table height (or null not to set it) */ public static void calcColumnWidths(final JTable table, final Integer numRowsHeight, final Integer maxWidth) { if (table != null) { JTableHeader header = table.getTableHeader(); TableCellRenderer defaultHeaderRenderer = null; if (header != null) { defaultHeaderRenderer = header.getDefaultRenderer(); } TableColumnModel columns = table.getColumnModel(); TableModel data = table.getModel(); int margin = columns.getColumnMargin(); // only JDK1.3 int rowCount = data.getRowCount(); int totalWidth = 0; for (int i = columns.getColumnCount() - 1; i >= 0; --i) { TableColumn column = columns.getColumn(i); int columnIndex = column.getModelIndex(); int width = -1; TableCellRenderer h = column.getHeaderRenderer(); if (h == null) h = defaultHeaderRenderer; if (h != null) // Not explicitly impossible { Component c = h.getTableCellRendererComponent(table, column.getHeaderValue(), false, false, -1, i); width = c.getPreferredSize().width; } for (int row = rowCount - 1; row >= 0; --row) { TableCellRenderer r = table.getCellRenderer(row, i); Component c = r.getTableCellRendererComponent(table, data.getValueAt(row, columnIndex), false, false, row, i); width = Math.max(width, c.getPreferredSize().width + 10); // adding an arbitray 10 pixels to make it look nicer if (maxWidth != null) { width = Math.min(width, maxWidth); } } if (width >= 0) { column.setPreferredWidth(width + margin); // <1.3: without margin } else { // ??? } totalWidth += column.getPreferredWidth(); } // If you like; This does not make sense for two many columns! Dimension size = table.getPreferredScrollableViewportSize(); //if (totalWidth > size.width) { if (numRowsHeight != null) { size.height = Math.min(size.height, table.getRowHeight() * numRowsHeight); } size.width = totalWidth; table.setPreferredScrollableViewportSize(size); } } }
From source file:com.mirth.connect.client.ui.ChannelSetup.java
private void waitForPreviousCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_waitForPreviousCheckboxActionPerformed currentChannel.getDestinationConnectors().get(destinationTable.getSelectedModelIndex()) .setWaitForPrevious(waitForPreviousCheckbox.isSelected()); TableModel model = destinationTable.getModel(); int rowCount = model.getRowCount(); int colNum = destinationTable.getColumnModelIndex(DESTINATION_CHAIN_COLUMN_NAME); boolean waitForPrevious = waitForPreviousCheckbox.isSelected(); for (int i = destinationTable.getSelectedModelIndex(); i < rowCount; i++) { Integer chain = (Integer) model.getValueAt(i, colNum); chain += (waitForPrevious) ? -1 : 1; model.setValueAt(chain, i, colNum); }//from www . java2 s . co m }