List of usage examples for javax.swing JTable getRowCount
@BeanProperty(bound = false) public int getRowCount()
JTable
, given unlimited space. From source file:modnlp.capte.AlignmentInterfaceWS.java
public static void packRows(JTable table, int margin) { packRows(table, 0, table.getRowCount(), margin); }
From source file:funcoes.funcoes.java
public static double calculaTotalMedia(JTable tabela, int coluna, String tipo, int denominador) throws ParseException { double valorTotal = 0.0; double valorAdd = 0.0; for (int a = 1; a <= tabela.getRowCount(); a++) { try {/*from w w w . j a va2 s. co m*/ valorAdd = Double .parseDouble(funcoes.formatoParaInserir(tabela.getValueAt(a - 1, coluna).toString())); if (valorAdd < 0.0 && tipo.equalsIgnoreCase("-")) { valorTotal = valorTotal + valorAdd; } else { if (valorAdd >= 0.0 && tipo.equalsIgnoreCase("+")) { valorTotal = valorTotal + valorAdd; } else { if (tipo.equalsIgnoreCase("0")) { valorTotal = valorTotal + valorAdd; } } } } catch (NullPointerException ex) { } } return valorTotal / denominador; }
From source file:funcoes.funcoes.java
public static String calculaTotalFormatoDinheiro(JTable tabela, int coluna, String tipo) throws ParseException { double valorTotal = 0.0; double valorAdd = 0.0; String retorno = null;//from w w w .jav a 2 s.c o m for (int a = 1; a <= tabela.getRowCount(); a++) { valorAdd = Double.parseDouble(funcoes.formatoParaInserir(tabela.getValueAt(a - 1, coluna).toString() .substring(3, tabela.getValueAt(a - 1, coluna).toString().length()))); if (valorAdd < 0.0 && tipo.equalsIgnoreCase("-")) { valorTotal = valorTotal + valorAdd; retorno = "R$ " + funcoes.paraFormatoDinheiro(valorTotal); } else { if (valorAdd >= 0.0 && tipo.equalsIgnoreCase("+")) { valorTotal = valorTotal + valorAdd; retorno = "R$ " + funcoes.paraFormatoDinheiro(valorTotal); } else { if (tipo.equalsIgnoreCase("0")) { valorTotal = valorTotal + valorAdd; retorno = "R$ " + funcoes.paraFormatoDinheiro(valorTotal); } } } } return retorno; }
From source file:modnlp.capte.AlignmentInterfaceWS.java
public static void packRows(JTable table, int start, int end, int margin) { for (int r = 0; r < table.getRowCount(); r++) { // Get the preferred height int h = getPreferredRowHeight(table, r, margin); // Now set the row height using the preferred height if (table.getRowHeight(r) != h) { table.setRowHeight(r, h);/*from ww w . j a v a 2 s . c o m*/ } } }
From source file:funcoes.funcoes.java
public static String calculaTotal(JTable tabela, int coluna, String tipo) throws ParseException { double valorTotal = 0.0; double valorAdd = 0.0; String retorno = null;//from w w w . j av a 2s. c o m for (int a = 1; a <= tabela.getRowCount(); a++) { try { valorAdd = Double .parseDouble(funcoes.formatoParaInserir(tabela.getValueAt(a - 1, coluna).toString())); if (valorAdd < 0.0 && tipo.equalsIgnoreCase("-")) { valorTotal = valorTotal + valorAdd; retorno = "R$ " + funcoes.paraFormatoDinheiro(valorTotal); } else { if (valorAdd >= 0.0 && tipo.equalsIgnoreCase("+")) { valorTotal = valorTotal + valorAdd; retorno = "R$ " + funcoes.paraFormatoDinheiro(valorTotal); } else { if (tipo.equalsIgnoreCase("0")) { valorTotal = valorTotal + valorAdd; retorno = "R$ " + funcoes.paraFormatoDinheiro(valorTotal); } } } } catch (NullPointerException ex) { } } return retorno; }
From source file:Main.java
/** * Pack specified column. Sets the preferred width of the specified visible * column so it is will be just wide enough to show the column head and the * widest cell value in the column + {@code margin} each side. * //www. j ava2s . c o m * Taken from http://www.exampledepot.com/egs/javax.swing.table/PackCol.html * * NB: If a table has more than 100 rows, then only the width of the column * header will be checked and not the widest cell value. Otherwise it could * take too long. * * @param table * table with column to pack * @param vColIndex * column to pack * @param margin * margin to leave at each side of the column (resulting in an * additional width of 2*margin pixels). */ public static void 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; // because checking the width of each row can be time consuming, // only do so if less than 101 rows. boolean checkDataWidth = (table.getRowCount() < 101); if (checkDataWidth) { // Get maximum width from all 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); }
From source file:Main.java
/** * Resizes the columns to match content while keeping the table the same * size. This means that the last column may be larger than the content. */// ww w .ja v a2 s . co m public static void resizeTableColumns(JTable table) { table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); int totalWidth = 0; for (int i = 0; i < table.getColumnCount(); i++) { DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel(); TableColumn col = colModel.getColumn(i); if (i == table.getColumnCount() - 1) { col.setPreferredWidth(table.getWidth() - totalWidth); table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); return; } int width = 0; TableCellRenderer renderer = col.getHeaderRenderer(); if (renderer == null) { renderer = table.getTableHeader().getDefaultRenderer(); } Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, -1, i); width = Math.max(width, comp.getPreferredSize().width); for (int r = 0; r < table.getRowCount(); r++) { renderer = table.getCellRenderer(r, i); comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, i), false, false, r, i); width = Math.max(width, comp.getPreferredSize().width); } totalWidth += width + 2; col.setPreferredWidth(width + 2); } }
From source file:net.sf.webphotos.util.Util.java
/** * PackColumn sets the preferred width of the visible column specified by * vColIndex. The column will be just wide enough to show the column head * and the widest cell in the column. margin pixels are added to the left * and right (resulting in an additional width of 2*margin pixels). * * @param table The table you want to resize a column. * @param vColIndex The column number./* w w w. j ava2s. co m*/ * @param margin Extra spaces for each side of column. */ public static void packColumn(JTable table, int vColIndex, int margin) { DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel(); TableColumn col = colModel.getColumn(vColIndex); int width; // Get width of column header javax.swing.table.TableCellRenderer renderer = col.getHeaderRenderer(); if (renderer == null) { renderer = table.getTableHeader().getDefaultRenderer(); } java.awt.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); }
From source file:LineChart.java
private static JFreeChart createDataset(JTable table) { TimeZone tz = TimeZone.getTimeZone("GMT"); XYDataset ds = null;// w ww . j a v a2 s . c o m if (table.getColumnCount() > 0) { Class klass = table.getColumnClass(0); if ((klass == Date.class) || (klass == Time.class) || (klass == c.Month.class) || (klass == c.Minute.class) || (klass == c.Second.class) || (klass == Timestamp.class)) { TimeSeriesCollection tsc = new TimeSeriesCollection(); for (int col = 1; col < table.getColumnCount(); col++) { TimeSeries series = null; try { if (klass == Date.class) { series = new TimeSeries(table.getColumnName(col), Day.class); for (int row = 0; row < table.getRowCount(); row++) { Date date = (Date) table.getValueAt(row, 0); Day day = new Day(date, tz); Object o = table.getValueAt(row, col); if (o instanceof Number) { ((TimeSeries) series).addOrUpdate(day, (Number) table.getValueAt(row, col)); } } } else if (klass == Time.class) { series = new TimeSeries(table.getColumnName(col), Millisecond.class); for (int row = 0; row < table.getRowCount(); row++) { Time time = (Time) table.getValueAt(row, 0); Millisecond ms = new Millisecond(time, tz); // Millisecond ms = new Millisecond(time); Object o = table.getValueAt(row, col); if (o instanceof Number) { series.addOrUpdate(ms, (Number) table.getValueAt(row, col)); } } } else if (klass == Timestamp.class) { series = new TimeSeries(table.getColumnName(col), Millisecond.class); for (int row = 0; row < table.getRowCount(); row++) { Timestamp time = (Timestamp) table.getValueAt(row, 0); Millisecond ms = new Millisecond(time, tz); Object o = table.getValueAt(row, col); if (o instanceof Number) { series.addOrUpdate(ms, (Number) table.getValueAt(row, col)); } } } else if (klass == c.Month.class) { series = new TimeSeries(table.getColumnName(col), Month.class); for (int row = 0; row < table.getRowCount(); row++) { c.Month time = (c.Month) table.getValueAt(row, 0); int m = time.i + 24000; int y = m / 12; m = 1 + m % 12; Month month = new Month(m, y); Object o = table.getValueAt(row, col); if (o instanceof Number) { series.addOrUpdate(month, (Number) table.getValueAt(row, col)); } } } else if (klass == c.Second.class) { series = new TimeSeries(table.getColumnName(col), Second.class); for (int row = 0; row < table.getRowCount(); row++) { c.Second time = (c.Second) table.getValueAt(row, 0); Second second = new Second(time.i % 60, time.i / 60, 0, 1, 1, 2001); Object o = table.getValueAt(row, col); if (o instanceof Number) { series.addOrUpdate(second, (Number) table.getValueAt(row, col)); } } } else if (klass == c.Minute.class) { series = new TimeSeries(table.getColumnName(col), Minute.class); for (int row = 0; row < table.getRowCount(); row++) { c.Minute time = (c.Minute) table.getValueAt(row, 0); Minute minute = new Minute(time.i % 60, time.i / 60, 1, 1, 2001); Object o = table.getValueAt(row, col); if (o instanceof Number) { series.addOrUpdate(minute, (Number) table.getValueAt(row, col)); } } } } catch (SeriesException e) { System.err.println("Error adding to series"); } if (series.getItemCount() > 0) tsc.addSeries(series); } ds = tsc; } else if ((klass == double.class) || (klass == int.class) || (klass == short.class) || (klass == long.class) || (klass == Time.class)) { XYSeriesCollection xysc = new XYSeriesCollection(); for (int col = 1; col < table.getColumnCount(); col++) { XYSeries series = null; try { series = new XYSeries(table.getColumnName(col)); for (int row = 0; row < table.getRowCount(); row++) { Number x = (Number) table.getValueAt(row, 0); Object y = table.getValueAt(row, col); if (y instanceof Number) { series.add(x, (Number) y); } } } catch (SeriesException e) { System.err.println("Error adding to series"); } if (series.getItemCount() > 0) xysc.addSeries(series); } ds = xysc; } } if (ds != null) { boolean legend = false; if (ds.getSeriesCount() > 1) { legend = true; } if (ds instanceof XYSeriesCollection) { return ChartFactory.createXYLineChart("", "", "", ds, PlotOrientation.VERTICAL, legend, true, true); } else if (ds instanceof TimeSeriesCollection) return ChartFactory.createTimeSeriesChart("", "", "", ds, legend, true, true); } return null; }
From source file:charts.ErroresPorMilChart.java
private DefaultCategoryDataset createDataset(JTable table) { DefaultCategoryDataset result = new DefaultCategoryDataset(); for (int row = 0; row < table.getRowCount(); row++) { String name = (String) table.getValueAt(row, 0); double quantity = (double) table.getValueAt(row, 1); result.setValue(quantity, name, ""); }//from w w w . j ava2 s. c o m return result; }