List of usage examples for javax.swing JTable getRowHeight
public int getRowHeight()
From source file:edu.ku.brc.ui.UIHelper.java
/** * Sizes the table to number of rows using getRowHeight * @param table the table to be sized//from ww w . ja va 2 s. co m * @param rows the number of rows */ public static void setVisibleRowCount(final JTable table, final int rows) { if (table != null) { table.setPreferredScrollableViewportSize( new Dimension(table.getPreferredScrollableViewportSize().width, rows * table.getRowHeight())); } }
From source file:fs.MainWindow.java
public void GenerateTable(Object[][] data, String title, String subtitle, final String[] titles) { JFrame window = new JFrame(title); window.setLayout(new java.awt.BorderLayout(5, 5)); JLabel label = new JLabel(subtitle); label.setFont(new java.awt.Font("Tahoma", 1, 12)); label.setForeground(new java.awt.Color(0, 0, 255)); label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); label.setOpaque(true);//w w w. java 2 s . co m label.setPreferredSize(new java.awt.Dimension(50, 30)); ListModel lm = new AbstractListModel() { String headers[] = titles; @Override public int getSize() { return headers.length; } @Override public Object getElementAt(int index) { return headers[index]; } }; // String[] titles = getClasses(); JList rowHeader = new JList(lm); rowHeader.setFixedCellWidth(50); JTable jTable = new JTable(data, titles); rowHeader.setFixedCellHeight(jTable.getRowHeight()); rowHeader.setCellRenderer(new RowHeaderRenderer(jTable)); JScrollPane scroll = new JScrollPane(jTable); scroll.setRowHeaderView(rowHeader); getContentPane().add(scroll, BorderLayout.CENTER); jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jTable.setAlignmentX(JTable.CENTER_ALIGNMENT); window.add(label, java.awt.BorderLayout.NORTH); window.add(scroll, java.awt.BorderLayout.CENTER); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); window.setBounds((screenSize.width - 800) / 2, (screenSize.height - 270) / 2, 800, 270); window.setVisible(true); }
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. * //from ww w .j a v a 2 s. co m * @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:edu.ku.brc.specify.conversion.GenericDBConversion.java
/** * @return/*from www . j a va2s . c om*/ */ public CollectionResultType initialize() { collectionInfoList = CollectionInfo.getCollectionInfoList(oldDBConn, false); //fixIdaho(); if (collectionInfoList == null) { if (CollectionInfo.isAskForFix()) { if (ConvertTaxonHelper.fixTaxonomicUnitType(oldDBConn)) { collectionInfoList = CollectionInfo.getCollectionInfoList(oldDBConn, true); } else { try { oldDBConn.close(); } catch (SQLException e) { } System.exit(0); } } else { try { oldDBConn.close(); } catch (SQLException e) { } System.exit(0); } } collectionInfoShortList = CollectionInfo.getFilteredCollectionInfoList(); if (collectionInfoList != null && collectionInfoList.size() > 0) { int paleoCnt = 0; // This is a Hash of TaxonObjectType to see how many collections use the same TaxonObjectType HashMap<Integer, HashSet<CollectionInfo>> taxonomyTypeHash = new HashMap<Integer, HashSet<CollectionInfo>>(); // Get a List for each type of Paleo Collection, hashed by the Root Id HashMap<Integer, Vector<CollectionInfo>> paleoColInfoHash = new HashMap<Integer, Vector<CollectionInfo>>(); HashMap<Integer, HashSet<DisciplineType.STD_DISCIPLINES>> paleoDispTypeHash = new HashMap<Integer, HashSet<DisciplineType.STD_DISCIPLINES>>(); for (CollectionInfo colInfo : collectionInfoShortList) { // Tracks a 'set' of CollectionInfo objects for each TaxonomyTypeId HashSet<CollectionInfo> taxonomyTypeSet = taxonomyTypeHash.get(colInfo.getTaxonomyTypeId()); if (taxonomyTypeSet == null) { System.out.println("Creating TxTypeID: " + colInfo.getTaxonomyTypeId() + " From " + colInfo.getCatSeriesName()); taxonomyTypeSet = new HashSet<CollectionInfo>(); taxonomyTypeHash.put(colInfo.getTaxonomyTypeId(), taxonomyTypeSet); } else { System.out.println("Adding TxTypeID: " + colInfo.getTaxonomyTypeId() + " From " + colInfo.getCatSeriesName() + " " + taxonomyTypeSet.size()); } taxonomyTypeSet.add(colInfo); //--- DisciplineType dType = getStandardDisciplineName(colInfo.getTaxonomyTypeName(), colInfo.getColObjTypeName(), colInfo.getCatSeriesName()); colInfo.setDisciplineTypeObj(dType); if (dType != null && dType.isPaleo()) { Vector<CollectionInfo> ciList = paleoColInfoHash.get(colInfo.getTaxonNameId()); if (ciList == null) { ciList = new Vector<CollectionInfo>(); paleoColInfoHash.put(colInfo.getTaxonNameId(), ciList); } ciList.add(colInfo); HashSet<DisciplineType.STD_DISCIPLINES> typeDispSet = paleoDispTypeHash .get(colInfo.getTaxonNameId()); if (typeDispSet == null) { typeDispSet = new HashSet<DisciplineType.STD_DISCIPLINES>(); paleoDispTypeHash.put(colInfo.getTaxonNameId(), typeDispSet); } typeDispSet.add(colInfo.getDisciplineTypeObj().getDisciplineType()); paleoCnt++; } System.out.println("--------------------------------------"); //System.out.println(colInfo.toString()+"\n"); } // for loop int cnt = 0; StringBuilder msg = new StringBuilder(); for (Integer taxonomyTypId : taxonomyTypeHash.keySet()) { HashSet<CollectionInfo> taxonomyTypeSet = taxonomyTypeHash.get(taxonomyTypId); if (taxonomyTypeSet.size() > 1) { msg.append( String.format("<html>TaxonomyTypeId %d has more than one Discpline/Collection:<br><OL>", taxonomyTypId)); for (CollectionInfo ci : taxonomyTypeSet) { msg.append(String.format("<LI>%s - %s - %s</LI>", ci.getCatSeriesName(), ci.getColObjTypeName(), ci.getTaxonomyTypeName())); } msg.append("</OL>"); cnt++; } } if (cnt > 0) { JOptionPane.showConfirmDialog(null, msg.toString(), "Taxomony Type Issues", JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE); } // Will be zero for no Paleo collections if (paleoCnt > 1) { // Check to see if they all use the same tree if (paleoColInfoHash.size() > 1) { msg.setLength(0); // We get here when there is more than one Taxon Tree for the Paleo Collections for (Integer treeId : paleoColInfoHash.keySet()) { Vector<CollectionInfo> ciList = paleoColInfoHash.get(treeId); CollectionInfo colInfo = ciList.get(0); msg.append(String.format("The following collections use Taxon Tree '%s':\n", colInfo.getTaxonomyTypeName())); for (CollectionInfo ci : paleoColInfoHash.get(treeId)) { DisciplineType dType = getStandardDisciplineName(ci.getTaxonomyTypeName(), ci.getColObjTypeName(), ci.getCatSeriesName()); String name = String.format("%s / %s / %s / %s / %s", ci.getCatSeriesPrefix(), ci.getCatSeriesName(), ci.getColObjTypeName(), ci.getTaxonomyTypeName(), dType.toString()); msg.append(name); msg.append("\n"); } msg.append("\n"); } JOptionPane.showConfirmDialog(null, msg.toString(), "Paleo Taxon Tree Issues", JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE); } else { StringBuilder colNames = new StringBuilder(); for (Integer treeId : paleoColInfoHash.keySet()) { for (CollectionInfo ci : paleoColInfoHash.get(treeId)) { colNames.append("<LI>"); colNames.append(ci.getCatSeriesName()); colNames.append("</LI>"); } } // You get here when all the Paleo Disciplines use the same tree String msgStr = "<html>All the Paleo Collections need to use the same Taxon Tree and<br>therefore needs to be in the same discipline:<br><ol>"; JOptionPane.showConfirmDialog(null, msgStr + colNames.toString(), "Paleo Taxon Tree Issues", JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE); for (Integer treeId : paleoColInfoHash.keySet()) { Vector<CollectionInfo> ciList = paleoColInfoHash.get(treeId); CollectionInfo colInfo = ciList.get(0); for (CollectionInfo ci : paleoColInfoHash.get(treeId)) { ci.setDisciplineTypeObj(colInfo.getDisciplineTypeObj()); } } } // } DefaultTableModel model = CollectionInfo.getCollectionInfoTableModel(false); if (model.getRowCount() > 1) { TableWriter colInfoTblWriter = convLogger.getWriter("colinfo.html", "Collection Info"); colInfoTblWriter.startTable(); colInfoTblWriter.logHdr(CollectionInfoModel.getHeaders()); Object[] row = new Object[model.getColumnCount()]; for (int r = 0; r < model.getRowCount(); r++) { for (int i = 0; i < model.getColumnCount(); i++) { row[i] = model.getValueAt(r, i); } colInfoTblWriter.logObjRow(row); } colInfoTblWriter.endTable(); colInfoTblWriter.println("<BR><h3>Collections to be Created.</h3>"); colInfoTblWriter.startTable(); colInfoTblWriter.logHdr(CollectionInfoModel.getHeaders()); model = CollectionInfo.getCollectionInfoTableModel(true); row = new Object[model.getColumnCount()]; for (int r = 0; r < model.getRowCount(); r++) { for (int i = 0; i < model.getColumnCount(); i++) { row[i] = model.getValueAt(r, i); } colInfoTblWriter.logObjRow(row); } colInfoTblWriter.endTable(); colInfoTblWriter.close(); File file = new File(colInfoTblWriter.getFileName()); if (file != null && file.exists()) { try { AttachmentUtils.openURI(file.toURI()); } catch (Exception ex) { ex.printStackTrace(); } } } for (CollectionInfo ci : CollectionInfo.getFilteredCollectionInfoList()) { String sql = "select preparationmethod, ct.* from usyscollobjprepmeth pt inner join usysmetafieldsetsubtype st on st.fieldsetsubtypeid = pt.fieldsetsubtypeid " + "inner join collectionobjecttype ct1 on ct1.collectionobjecttypeid = st.fieldvalue " + "inner join collectionobjecttype ct on ct.collectionobjecttypename = replace(ct1.collectionobjecttypename, ' Preparation', '') " + "inner join catalogseriesdefinition csd on csd.objecttypeid = ct.collectionobjecttypeid " + "inner join catalogseries cs on cs.catalogseriesid = csd.catalogseriesid " + "WHERE csd.catalogseriesid = " + ci.getCatSeriesId(); System.out.println("\n------------------"); System.out.println(ci.getCatSeriesName()); System.out.println(sql); System.out.println("------------------"); int i = 0; Vector<Object[]> list = BasicSQLUtils.query(oldDBConn, sql); if (list.size() > 0) { for (Object[] row : list) { System.out.print(i + " - "); for (Object col : row) { System.out.print(col != null ? col.toString() : "null"); System.out.print(", "); } System.out.println(); i++; } } else { System.out.println("No Results"); } sql = "select ct.*, (select relatedsubtypevalues from usysmetacontrol c " + "left join usysmetafieldsetsubtype fst on fst.fieldsetsubtypeid = c.fieldsetsubtypeid " + "where objectid = 10290 and ct.taxonomytypeid = c.relatedsubtypevalues) as DeterminationTaxonType " + "from collectiontaxonomytypes ct where ct.biologicalobjecttypeid = " + ci.getColObjTypeId(); sql = String.format( "SELECT CollectionTaxonomyTypesID, BiologicalObjectTypeID, CollectionObjectTypeName FROM (select ct.*, " + "(SELECT distinct relatedsubtypevalues FROM usysmetacontrol c " + "LEFT JOIN usysmetafieldsetsubtype fst ON fst.fieldsetsubtypeid = c.fieldsetsubtypeid " + "WHERE objectid = 10290 AND ct.taxonomytypeid = c.relatedsubtypevalues) AS DeterminationTaxonType " + "FROM collectiontaxonomytypes ct WHERE ct.biologicalobjecttypeid = %d) T1 " + "INNER JOIN collectionobjecttype cot ON T1.biologicalobjecttypeid = cot.CollectionObjectTypeID", ci.getColObjTypeId()); System.out.println("\n------------------"); System.out.println(ci.getColObjTypeName()); System.out.println(sql); System.out.println("------------------"); i = 0; list = BasicSQLUtils.query(oldDBConn, sql); if (list.size() > 0) { for (Object[] row : list) { System.out.print(i + " - "); for (Object col : row) { System.out.print(col != null ? col.toString() : "null"); System.out.print(", "); } System.out.println(); i++; } } else { System.out.println("No Results"); } } /* String sql = " select ct.*, (select relatedsubtypevalues from usysmetacontrol c " + "left join usysmetafieldsetsubtype fst on fst.fieldsetsubtypeid = c.fieldsetsubtypeid " + "where objectid = 10290 and ct.taxonomytypeid = c.relatedsubtypevalues) as DeterminationTaxonType " + "from collectiontaxonomytypes ct where ct.biologicalobjecttypeid = 13"; System.out.println("\n------------------"); System.out.println("List of the taxonomytypes associated with a CollectionObjectTypeID"); System.out.println(sql); System.out.println("------------------"); int i = 0; Vector<Object[]> list = BasicSQLUtils.query(oldDBConn, sql); if (list.size() > 0) { for (Object[] row : list) { System.out.print(i+" - "); for (Object col: row) { System.out.print(col != null ? col.toString() : "null"); System.out.print(", "); } System.out.println(); } } else { System.out.println("No Results"); }*/ CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,2px,f:p:g,10px,p,2px,p:g,8px")); JTable tableTop = new JTable(CollectionInfo.getCollectionInfoTableModel(false)); JTable tableBot = new JTable( CollectionInfo.getCollectionInfoTableModel(!CollectionInfo.DOING_ACCESSSION)); int rows = 10; tableTop.setPreferredScrollableViewportSize(new Dimension( tableTop.getPreferredScrollableViewportSize().width, rows * tableTop.getRowHeight())); tableBot.setPreferredScrollableViewportSize(new Dimension( tableBot.getPreferredScrollableViewportSize().width, rows * tableBot.getRowHeight())); pb.add(UIHelper.createLabel("Available Specify 5 Taxononmic Types", SwingConstants.CENTER), cc.xy(1, 1)); pb.add(UIHelper.createScrollPane(tableTop), cc.xy(1, 3)); pb.add(UIHelper.createLabel("Specify 5 Collections to be Created", SwingConstants.CENTER), cc.xy(1, 5)); pb.add(UIHelper.createScrollPane(tableBot), cc.xy(1, 7)); pb.setDefaultDialogBorder(); CustomDialog dlg = new CustomDialog(null, "Taxononic Types", true, pb.getPanel()); dlg.createUI(); dlg.setSize(1024, 500); UIHelper.centerWindow(dlg); dlg.setAlwaysOnTop(true); dlg.setVisible(true); if (dlg.isCancelled()) { return CollectionResultType.eCancel; } Pair<CollectionInfo, DisciplineType> pair = CollectionInfo.getDisciplineType(oldDBConn); if (pair == null || pair.second == null) { CollectionInfo colInfo = pair.first; disciplineType = getStandardDisciplineName(colInfo.getTaxonomyTypeName(), colInfo.getColObjTypeName(), colInfo.getCatSeriesName()); } else { disciplineType = pair.second; } return disciplineType != null ? CollectionResultType.eOK : CollectionResultType.eError; } return CollectionResultType.eError; }
From source file:org.apache.jmeter.util.JMeterUtils.java
/** * Apply HiDPI mode management to {@link JTable} * @param table the {@link JTable} which should be adapted for HiDPI mode *//*from w w w. j a v a2s .c om*/ public static void applyHiDPI(JTable table) { if (JMeterUtils.getHiDPIMode()) { table.setRowHeight((int) Math.round(table.getRowHeight() * JMeterUtils.getHiDPIScaleFactor())); } }
From source file:org.datanucleus.ide.idea.ui.DNEConfigForm.java
private static void setPreferredTableHeight(final JTable table, final int rows) { final int width = table.getPreferredSize().width; final int height = rows * table.getRowHeight(); table.setPreferredSize(new Dimension(width, height)); }
From source file:org.tellervo.desktop.io.ImportDialog.java
@SuppressWarnings("unused") private static void updateRowHeights(JTable table) { try {/* www .ja v a 2 s .c om*/ 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) { } }