List of usage examples for javax.swing JTable getColumnName
public String getColumnName(int column)
column
. From source file:Main.java
public static void setTableColumnsAlignment(int[] colAlignments, JTable table) { for (int i = 0; i < table.getColumnCount(); i++) { if (colAlignments[i] == JLabel.LEFT) continue; TableColumn col = table.getColumn(table.getColumnName(i)); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(colAlignments[i]); col.setCellRenderer(renderer);/* ww w .j a v a2s . c o m*/ } }
From source file:OAT.ui.util.UiUtil.java
public static void setupColumns(JTable table) { for (int i = 0; i < table.getColumnCount(); i++) { DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); TableColumn column = table.getColumnModel().getColumn(i); Class columnClass = table.getColumnClass(i); String columnName = table.getColumnName(i); renderer.setToolTipText(columnName); if (columnClass.getSuperclass().equals(Number.class)) { renderer.setHorizontalAlignment(DefaultTableCellRenderer.RIGHT); }/*from w w w .ja v a2 s .c o m*/ if (table.isEnabled()) { if (columnName.equals("Currency")) { //addComboCell(column, Product.CURRENCIES); } else if (columnName.equals("Holidays")) { //column.setCellEditor(new FileChooserCellEditor()); } } column.setCellRenderer(renderer); } }
From source file:LineChart.java
private static JFreeChart createDataset(JTable table) { TimeZone tz = TimeZone.getTimeZone("GMT"); XYDataset ds = null;/* w w w . j ava2 s. c om*/ 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:com.sec.ose.osi.ui.frm.main.identification.stringmatch.table.JTableInfoForSMFile.java
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JComponent comp = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);// ww w. ja v a 2 s .c o m if (value != null) { if (table.getColumnName(column).equals("Version") || table.getColumnName(column).equals("Pending Hits") || table.getColumnName(column).equals("Status") || table.getColumnName(column).equals("Identified Hits") || table.getColumnName(column).equals("Files")) { setHorizontalAlignment(SwingConstants.CENTER); } else { setHorizontalAlignment(SwingConstants.LEFT); } comp.setToolTipText(String.valueOf(value)); if (table.getValueAt(row, TableModelForSMFile.COL_STATUS) != null && table.getValueAt(row, TableModelForSMFile.COL_STATUS).toString().equals("Identified")) { comp.setFont(new Font("Arial", Font.BOLD | Font.ITALIC, 12)); comp.setForeground(new Color(20, 20, 20)); } else if (table.getValueAt(row, TableModelForSMFile.COL_STATUS).toString().equals("Declared")) { comp.setForeground(new Color(150, 150, 150)); } else { comp.setForeground(new Color(20, 20, 20)); } } else { comp.setToolTipText(null); } return comp; }
From source file:edu.ucla.stat.SOCR.chart.demo.NormalDistributionDemo.java
/** * use demo data to reset JTable and redraw the graph *//*from w ww . j ava 2s.c o m*/ public void resetExample() { XYDataset dataset = createDataset(true); JFreeChart chart = createChart(dataset); chartPanel = new ChartPanel(chart, false); setChart(); hasExample = true; convertor.normalDataset2Table(mean, stdDev); JTable tempDataTable = convertor.getTable(); resetTableRows(tempDataTable.getRowCount() + 1); resetTableColumns(tempDataTable.getColumnCount() + 2); for (int i = 0; i < tempDataTable.getColumnCount(); i++) { columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i)); // System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i)); } columnModel = dataTable.getColumnModel(); dataTable.setTableHeader(new EditableHeader(columnModel)); for (int i = 0; i < tempDataTable.getRowCount(); i++) for (int j = 0; j < tempDataTable.getColumnCount(); j++) { dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j); } dataPanel.removeAll(); dataPanel.add(new JScrollPane(dataTable)); dataTable.setGridColor(Color.gray); dataTable.setShowGrid(true); dataTable.doLayout(); // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003 try { dataTable.setDragEnabled(true); } catch (Exception e) { } dataPanel.validate(); // do the mapping int columnCount = dataTable.getColumnCount(); for (int i = 0; i < columnCount / 2 - 1; i++) { addButtonIndependent(); addButtonDependent(); } //updateStatus(url); }
From source file:edu.ucla.stat.SOCR.chart.demo.IndexChart.java
public void resetExample() { // System.out.println("resetExample get called"); XYDataset dataset = createDataset1(true); JFreeChart chart = createChart(dataset); chartPanel = new ChartPanel(chart, false); setChart();/*from w w w .jav a 2 s . c o m*/ hasExample = true; // System.out.println("row_count="+row_count); // System.out.println("raw+x="+raw_x[0]); convertor.Y2Table(raw_x, row_count); //convertor.dataset2Table(dataset); JTable tempDataTable = convertor.getTable(); resetTableRows(tempDataTable.getRowCount() + 1); resetTableColumns(tempDataTable.getColumnCount()); for (int i = 0; i < tempDataTable.getColumnCount(); i++) { columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i)); // System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i)); } columnModel = dataTable.getColumnModel(); dataTable.setTableHeader(new EditableHeader(columnModel)); for (int i = 0; i < tempDataTable.getRowCount(); i++) for (int j = 0; j < tempDataTable.getColumnCount(); j++) { dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j); } dataPanel.removeAll(); dataPanel.add(new JScrollPane(dataTable)); dataTable.setGridColor(Color.gray); dataTable.setShowGrid(true); dataTable.doLayout(); // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003 try { dataTable.setDragEnabled(true); } catch (Exception e) { } dataPanel.validate(); // do the mapping addButtonIndependent();//Y updateStatus(url); }
From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo3.java
/** * reset dataTable to default (demo data), and refesh chart *///from w ww.j ava 2 s.c o m public void resetExample() { isDemo = true; IntervalXYDataset dataset = createDataset(isDemo); JFreeChart chart = createChart(dataset); chartPanel = new ChartPanel(chart, false); setChart(); hasExample = true; convertor.dataset2Table((TimeSeriesCollection) dataset); JTable tempDataTable = convertor.getTable(); int seriesCount = tempDataTable.getColumnCount() / 2; resetTableRows(tempDataTable.getRowCount() + 1); resetTableColumns(seriesCount * 2); for (int i = 0; i < seriesCount * 2; i++) { columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i)); // System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i)); } columnModel = dataTable.getColumnModel(); dataTable.setTableHeader(new EditableHeader(columnModel)); for (int i = 0; i < tempDataTable.getRowCount(); i++) for (int j = 0; j < tempDataTable.getColumnCount(); j++) { dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j); } dataPanel.removeAll(); dataPanel.add(new JScrollPane(dataTable)); dataTable.setGridColor(Color.gray); dataTable.setShowGrid(true); // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003 try { dataTable.setDragEnabled(true); } catch (Exception e) { } dataPanel.validate(); // do the mapping for (int i = 0; i < seriesCount; i++) { addButtonIndependent(); addButtonDependent(); } updateStatus(url); }
From source file:edu.ucla.stat.SOCR.chart.SuperXYChart_Time.java
/** * reset dataTable to default (demo data), and refesh chart *//*from ww w .j a v a 2s . c o m*/ public void resetExample() { dataset = createDataset(true); JFreeChart chart = createChart(dataset); chartPanel = new ChartPanel(chart, false); setChart(); hasExample = true; convertor.dataset2Table((TimeSeriesCollection) dataset); JTable tempDataTable = convertor.getTable(); //resetTable(); resetTableRows(tempDataTable.getRowCount()); resetTableColumns(tempDataTable.getColumnCount()); for (int i = 0; i < tempDataTable.getColumnCount(); i++) { columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i)); // System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i)); } columnModel = dataTable.getColumnModel(); dataTable.setTableHeader(new EditableHeader(columnModel)); for (int i = 0; i < tempDataTable.getRowCount(); i++) for (int j = 0; j < tempDataTable.getColumnCount(); j++) { dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j); } dataPanel.removeAll(); dataPanel.add(new JScrollPane(dataTable)); dataTable.setGridColor(Color.gray); dataTable.setShowGrid(true); dataTable.doLayout(); // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003 try { dataTable.setDragEnabled(true); } catch (Exception e) { } dataPanel.validate(); // do the mapping setMapping(); updateStatus(url); }
From source file:edu.ucla.stat.SOCR.chart.demo.MultiIndexChart.java
public void resetExample() { // System.out.println("resetExample get called"); XYDataset dataset = createDataset1(true); JFreeChart chart = createChart(dataset); chartPanel = new ChartPanel(chart, false); setChart();//w w w . j av a 2 s.c o m hasExample = true; //System.out.println("independentVarLength="+independentVarLength); // System.out.println("raw+x="+raw_x[0]); int colCount = dataset.getSeriesCount(); String[] columnName = new String[colCount]; for (int i = 0; i < colCount; i++) columnName[i] = dataset.getSeriesKey(i).toString(); convertor.multiY2Table(raw_x2, row_count, colCount, columnName); //convertor.dataset2Table(dataset); JTable tempDataTable = convertor.getTable(); resetTableRows(tempDataTable.getRowCount() + 1); resetTableColumns(tempDataTable.getColumnCount()); for (int i = 0; i < tempDataTable.getColumnCount(); i++) { columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i)); // System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i)); } columnModel = dataTable.getColumnModel(); dataTable.setTableHeader(new EditableHeader(columnModel)); for (int i = 0; i < tempDataTable.getRowCount(); i++) for (int j = 0; j < tempDataTable.getColumnCount(); j++) { dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j); //System.out.println("setTabledata "+tempDataTable.getValueAt(i,j)); } dataPanel.removeAll(); dataPanel.add(new JScrollPane(dataTable)); dataTable.setGridColor(Color.gray); dataTable.setShowGrid(true); dataTable.doLayout(); // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003 try { dataTable.setDragEnabled(true); } catch (Exception e) { } dataPanel.validate(); // do the mapping for (int i = 0; i < colCount; i++) addButtonIndependent();//Y rangeLabel = ""; for (int j = 0; j < colCount; j++) rangeLabel += columnName[j] + "/"; rangeLabel = rangeLabel.substring(0, rangeLabel.length() - 1); updateStatus(url); }
From source file:edu.ucla.stat.SOCR.chart.demo.EventFrequencyDemo1.java
public void resetExample() { dataset = createDataset(true);/*w ww .ja va 2s. co m*/ JFreeChart chart = createChart(dataset); chartPanel = new ChartPanel(chart, false); // setSummary(dataset); setChart(); hasExample = true; convertor.dataset2Table(dataset); JTable tempDataTable = convertor.getTable(); resetTableRows(tempDataTable.getRowCount() + 1); resetTableColumns(tempDataTable.getColumnCount() + 1); for (int i = 0; i < tempDataTable.getColumnCount(); i++) { columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i)); // System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i)); } columnModel = dataTable.getColumnModel(); dataTable.setTableHeader(new EditableHeader(columnModel)); DecimalFormat f = new DecimalFormat("#.#E0"); for (int i = 0; i < tempDataTable.getRowCount(); i++) for (int j = 0; j < tempDataTable.getColumnCount(); j++) { if (j != 0) { try { long time = f.parse((String) tempDataTable.getValueAt(i, j)).longValue(); Date date = new Date(time); dataTable.setValueAt(new Day(date).toString(), i, j); } catch (ParseException e) { dataTable.setValueAt("NaN", i, j); } } else dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j); } dataPanel.removeAll(); dataPanel.add(new JScrollPane(dataTable)); dataTable.setGridColor(Color.gray); dataTable.setShowGrid(true); dataTable.doLayout(); // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003 try { dataTable.setDragEnabled(true); } catch (Exception e) { } dataPanel.validate(); // do the mapping addButtonDependent(); int columnCount = dataset.getColumnCount(); for (int i = 0; i < columnCount; i++) addButtonIndependent(); updateStatus(url); }