List of usage examples for javax.swing JTable getColumnName
public String getColumnName(int column)
column
. From source file:edu.ucla.stat.SOCR.chart.SuperPieChart.java
/** * reset dataTable to default (demo data), and refesh chart *//*from w w w . j a v a 2 s .c o m*/ public void resetExample() { isDemo = true; dataset = createDataset(true); JFreeChart chart = createChart(dataset); chartPanel = new ChartPanel(chart, false); setChart(); hasExample = true; if (!ThreeDPie) convertor.dataset2Table(dataset, pulloutFlag); else convertor.dataset2Table(dataset); JTable tempDataTable = convertor.getTable(); // resetTable(); 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)); 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("setting dataTable :"+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 setMapping(); updateStatus(url); }
From source file:gdt.jgui.tool.JEntityEditor.java
private void showElement(Sack entity, String element$) { try {// w w w. j a v a 2 s . c o m // System.out.println("EntityEditor:showElement:"+element$); Core[] ca = null; if ("attributes".equals(element$)) ca = entity.attributesGet(); else ca = entity.elementGet(element$); final JTable table = new JTable(); DefaultTableModel model = new DefaultTableModel(null, new String[] { "type", "name", "value" }); table.setModel(model); table.getTableHeader().setDefaultRenderer(new SimpleHeaderRenderer()); table.getTableHeader().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int col = table.columnAtPoint(e.getPoint()); String name = table.getColumnName(col); // System.out.println("Column index selected " + col + " " + name); sort(name); } }); JScrollPane scrollPane = new JScrollPane(); tabbedPane.add(element$, scrollPane); scrollPane.add(table); scrollPane.setViewportView(table); if (ca != null) for (Core aCa : ca) { model.addRow(new String[] { aCa.type, aCa.name, aCa.value }); } } catch (Exception e) { LOGGER.severe(e.toString()); } }
From source file:com.puzzle.gui.MainFrame.java
/** * table?/*w w w. j a v a 2s .c o m*/ * * @param table */ public static void makeJtableFace(javax.swing.JTable table) { try { DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() { public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (row % 2 == 0) { setBackground(java.awt.Color.white); // } else if (row % 2 == 1) { setBackground(new java.awt.Color(206, 231, 255)); //? } return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } }; for (int i = 0; i < table.getColumnCount(); i++) { table.getColumn(table.getColumnName(i)).setCellRenderer(tcr); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:edu.ucla.stat.SOCR.chart.demo.SOCR_EM_MixtureModelChartDemo.java
public void resetExample() { XYDataset dataset = createDataset(true); // System.out.println("resetExample num_series="+num_series); XYDataset[] ds1 = new XYDataset[num_series]; ds1[0] = dataset;/*w ww. j av a2 s .co m*/ kernels = null; chart = createChart(ds1); refreshChartPanel(); setChart(); hasExample = true; // convertor.dataset2Table((TimeSeriesCollection)dataset); 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 int columnCount = dataTable.getColumnCount(); for (int i = 0; i < columnCount / 2; i++) { //System.out.println("mapping"); addButtonIndependent(); addButtonDependent(); } getMapping(); // System.out.println("resetExample get called indepvar"+independentVarLength ); updateStatus(url); }
From source file:edu.ucla.stat.SOCR.chart.demo.SOCR_EM_MixtureModelChartDemo.java
protected void setTable(XYDataset ds) { // update results table after segment //System.out.println("setTable get called"); //printDataset(ds); if (segment_flag) { // System.out.println("settable: setting segment resultTable"); resultsTables = new CustomJTable[num_series]; for (int s = 0; s < num_series; s++) { resultsTables[s] = mEMexperiment[s].getResultsTable(); }//from w ww .j a v a2 s .c o m } else { convertor.dataset2Table((XYDataset) ds); 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++) { String v = (String) tempDataTable.getValueAt(i, j); //if (v!="null" && v!="NaN") dataTable.setValueAt(v, i, j); } } //no segment // int columnCount = dataTable.getColumnCount(); //attention this is a quick fix for losted mapping, need revisit!!!!! for (int i = 0; i < num_series; i++) { //System.out.println("mapping"); addButtonIndependent(); addButtonDependent(); } setTablePane(); // don't bring graph to the front if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) != ALL) { // tabbedPanelContainer.setSelectedIndex(tabbedPanelContainer.indexOfComponent(graphPanel)); } else { setMixPanel(); } }
From source file:edu.ucla.stat.SOCR.chart.Chart.java
public void updateExample(ChartExampleData example) { // reset();// w w w .j ava2 s . co m hasExample = true; JTable tempDataTable = example.getExample(); /* if(tempDataTable.getRowCount()>dataTable.getRowCount()) appendTableRows(tempDataTable.getRowCount()-dataTable.getRowCount()); else */ resetTableRows(tempDataTable.getRowCount()); for (int i = 0; i < tempDataTable.getColumnCount(); i++) { columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i)); // System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i)); } dTableHeader = new EditableHeader(columnModel); dataTable.setTableHeader(dTableHeader); 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(); JScrollPane tablePanel = new JScrollPane(dataTable); tablePanel.setRowHeaderView(headerTable); dataPanel.add(tablePanel); dataPanel.add(new JScrollPane(summaryPanel)); 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(); //updateStatus("Example updated, please redo the mapping and update the chart"); }
From source file:net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.GenericWikiTableTransformer.java
/** * @see// w ww .j av a 2 s .c o m * net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.IWikiTableTransformer * #transform(javax.swing.JTable) */ @Override public String transform(JTable table) { int nbrSelRows = table.getSelectedRowCount(); int nbrSelCols = table.getSelectedColumnCount(); int[] selRows = table.getSelectedRows(); int[] selCols = table.getSelectedColumns(); if (selRows.length != 0 && selCols.length != 0) { StringBuilder buf = new StringBuilder(1024); // Start the table appendWithReplacement(buf, configuration.getTableStartTag()); // Create the header appendWithReplacement(buf, configuration.getHeaderStartTag()); for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx) { appendWithReplacement(buf, configuration.getHeaderCell(), table.getColumnName(selCols[colIdx])); } appendWithReplacement(buf, configuration.getHeaderEndTag()); // Now fill all the table rows for (int rowIdx = 0; rowIdx < nbrSelRows; ++rowIdx) { appendWithReplacement(buf, configuration.getRowStartTag()); for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx) { TableCellRenderer cellRenderer = table.getCellRenderer(selRows[rowIdx], selCols[colIdx]); Object cellObj = table.getValueAt(selRows[rowIdx], selCols[colIdx]); if (cellRenderer instanceof SquirrelTableCellRenderer) { cellObj = ((SquirrelTableCellRenderer) cellRenderer).renderValue(cellObj); } String value = null; if (cellObj == null) { value = ""; //$NON-NLS-1$ } else { final String tmp = cellObj.toString(); if (tmp.trim().equals("")) { //$NON-NLS-1$ value = ""; //$NON-NLS-1$ } else { value = tmp; } } appendWithReplacement(buf, configuration.getDataCell(), value); } appendWithReplacement(buf, configuration.getRowEndTag()); } appendWithReplacement(buf, configuration.getTableEndTag()); return buf.toString(); } else { return null; } }
From source file:org.yccheok.jstock.gui.JTableUtilities.java
public static void setJTableOptions(JTable jTable, GUIOptions.JTableOptions jTableOptions) { if (jTableOptions.getColumnSize() <= 0) { // A bug introduced in version 1.0.5p. Due to incorrect // implementation of Utils.toXML, we may get a table option with 0 // column turned on. To avoid all columns being turned off, we will // return early. return;// w w w . j a v a2s .co m } final Locale locale = jTableOptions.getLocale(); // HACKING! boolean first_column_hacking_required = false; // Remove unwanted column. MUST BE DONE FIRST! for (int i = 0; i < jTable.getColumnCount(); i++) { final String name = jTable.getColumnName(i); // In to avoid the following situation. // 1. GUIOptions is being saved when we are in Chinese locale. // 2. Application is restarted in English locale. // 3. We are trying to compare English wording with Chinese wording. // // Before performing comparison, we shall convert name, to the locale // of table options. final java.util.List<String> keys = getKeys(name, Locale.getDefault()); // Ensure correct resource file is being loaded. // When ResourceBundle.getBundle(..., locale) is being called, the // system will try to search in the following sequence. // 1. gui_<locale>.properties. // 2. gui_<default_locale>.properties. // 3. gui.properties. final Locale oldLocale = Locale.getDefault(); Locale.setDefault(locale); try { final ResourceBundle bundle = ResourceBundle.getBundle("org.yccheok.jstock.data.gui", locale); Locale.setDefault(oldLocale); // Try all the keys. boolean found = false; for (String key : keys) { final String translated_name = bundle.getString(key); if (jTableOptions.contains(translated_name)) { found = true; break; } } /* Remove any unwanted columns. */ if (found == false) { // HACKING! // Some customers complain their first column of Watchlist, // or Portfolio are being hidden. I'm not sure why that // happen. YES! I have really no idea why that happen! // This is a hacking way "if (i > 0)" to prevent such // problem. Shh... if (i > 0) { removeTableColumn(jTable, name); i--; } else { first_column_hacking_required = true; } } } finally { Locale.setDefault(oldLocale); } } final int optionsCount = jTableOptions.getColumnSize(); final int tableCount = jTable.getColumnCount(); // HACKING! // jTableOptions doesn't have first column information if first_column_hacking_required // is true. When perform column moving, we will start from 2nd column if // first_column_hacking_required is true. Assume first column will always // stay in first column. int target = first_column_hacking_required ? 1 : 0; /* Sort the columns according to user preference. */ for (int i = 0; i < optionsCount; i++) { final String name = jTableOptions.getColumnName(i); final java.util.List<String> keys = getKeys(name, locale); assert (keys != null); int index = -1; for (int j = 0; j < tableCount; j++) { // Try all the keys. boolean found = false; String translated_name = null; for (String key : keys) { translated_name = GUIBundle.getString(key); if (jTable.getColumnName(j).equals(translated_name)) { found = true; break; } } if (found) { /* Restore width. */ jTable.getColumn(translated_name).setPreferredWidth(jTableOptions.getColumnWidth(i)); index = j; break; } } if (index >= 0) { jTable.moveColumn(index, target++); } } }
From source file:org.yccheok.jstock.gui.PortfolioManagementJPanel.java
private void initTreeTableDefaultRenderer(JXTreeTable treeTable) { final TableCellRenderer doubleOldTableCellRenderer = treeTable.getDefaultRenderer(Double.class); treeTable.setDefaultRenderer(Double.class, new DefaultTableCellRenderer() { @Override// www. j a v a 2s.c om public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component c = doubleOldTableCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); final String UNITS = GUIBundle.getString("PortfolioManagementJPanel_Units"); // Do not manipulate display for "Units". We do not want 100 // "units" displayed as 100.00 "units". if (false == UNITS.equals(table.getColumnName(column))) { if (value != null) { if (c instanceof JLabel) { // Re-define the displayed value. // Ugly hacking. if (value instanceof DoubleWrapper) { DoubleWrapper v = (DoubleWrapper) value; ((JLabel) c).setText( org.yccheok.jstock.portfolio.Utils.toCurrency(v.decimalPlace, v.value)); } else if (value instanceof DoubleWithCurrency) { DoubleWithCurrency v = (DoubleWithCurrency) value; Currency currency = v.currency(); String content = org.yccheok.jstock.portfolio.Utils.toCurrency(v.decimalPlace(), v.Double()); if (currency == null) { ((JLabel) c).setText(content); } else { String prefix = currency.toString(); if (Currency.GBX.equals(prefix)) { // Special handling. prefix = Currency.GBP; } else if (Currency.ZAC.equals(prefix)) { // Special handling. prefix = Currency.ZAR; } ((JLabel) c).setText(prefix + " " + content); } } else { ((JLabel) c).setText( org.yccheok.jstock.portfolio.Utils.toCurrency(DecimalPlace.Four, value)); } } } } else { if (value != null) { if (c instanceof JLabel) { ((JLabel) c).setText(org.yccheok.jstock.portfolio.Utils.toUnits(value)); } } } return c; } }); treeTable.setDefaultRenderer(SimpleDate.class, new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value != null) { if (c instanceof JLabel) { DateFormat dateFormat = DateFormat.getDateInstance(); SimpleDate simpleDate = (SimpleDate) value; ((JLabel) c).setText(dateFormat.format(simpleDate.getTime())); } } return c; } }); }
From source file:org.yccheok.jstock.gui.PortfolioManagementJPanel.java
public boolean saveGUIOptions() { if (Utils.createCompleteDirectoryHierarchyIfDoesNotExist( org.yccheok.jstock.gui.Utils.getUserDataDirectory() + "config") == false) { return false; }// ww w . java2 s .co m final GUIOptions guiOptions = new GUIOptions(); final org.jdesktop.swingx.JXTreeTable[] treeTables = { buyTreeTable, sellTreeTable }; for (org.jdesktop.swingx.JXTreeTable treeTable : treeTables) { final javax.swing.table.JTableHeader jTableHeader = treeTable.getTableHeader(); final JTable jTable = jTableHeader.getTable(); final GUIOptions.JTableOptions jTableOptions = new GUIOptions.JTableOptions(); final int count = jTable.getColumnCount(); for (int i = 0; i < count; i++) { final String name = jTable.getColumnName(i); final TableColumn column = jTable.getColumnModel().getColumn(i); jTableOptions.addColumnOption( GUIOptions.JTableOptions.ColumnOption.newInstance(name, column.getWidth())); } guiOptions.addJTableOptions(jTableOptions); } guiOptions.addDividerLocation(jSplitPane1.getDividerLocation()); File f = new File(org.yccheok.jstock.gui.Utils.getUserDataDirectory() + "config" + File.separator + "portfoliomanagementjpanel.xml"); return org.yccheok.jstock.gui.Utils.toXML(guiOptions, f); }