List of usage examples for javax.swing JTable getColumn
public TableColumn getColumn(Object identifier)
TableColumn
object for the column in the table whose identifier is equal to identifier
, when compared using equals
. From source file:org.yccheok.jstock.gui.JTableUtilities.java
public static void insertTableColumnFromModel(JTable jTable, Object value, int clickedColumnIndex) { boolean isVisible = true; try {/*from w w w. ja v a 2 s . c om*/ TableColumn tableColumn = jTable.getColumn(value); } catch (java.lang.IllegalArgumentException exp) { isVisible = false; } if (isVisible) return; TableModel tableModel = jTable.getModel(); final int modelIndex = getModelColumnIndex(jTable, value); Class c = tableModel.getColumnClass(modelIndex); TableColumn tableColumn = new javax.swing.table.TableColumn(modelIndex, 0, jTable.getDefaultRenderer(c), jTable.getDefaultEditor(c)); jTable.addColumn(tableColumn); makeTableColumnWidthFit(jTable, jTable.getColumnCount() - 1, 5); // If we right clicked on the 3rd column, and select a new column, we // would like the new column to be inserted into 4th column. Note that, // clickedColumnIndex will be < 0, if we right clicked on empty area. if (clickedColumnIndex < 0) { // Have it in the last column when we right clicked on empty area. jTable.moveColumn(jTable.getColumnCount() - 1, jTable.getColumnCount() - 1); } else { // +1, as we want our newly inserted column to be at the right of // clicked column. jTable.moveColumn(jTable.getColumnCount() - 1, Math.min(jTable.getColumnCount() - 1, clickedColumnIndex + 1)); } }
From source file:org.yccheok.jstock.gui.JTableUtilities.java
public static int getModelColumnIndex(JTable jTable, Object value) { TableModel tableModel = jTable.getModel(); if (tableModel instanceof StockTableModel) { return ((StockTableModel) tableModel).findColumn(value.toString()); }/*from w w w . j ava 2 s .c o m*/ try { TableColumn tableColumn = jTable.getColumn(value); return tableColumn.getModelIndex(); } // Anti-pattern. We are depending on the exception throwing. Bad! catch (java.lang.IllegalArgumentException exp) { final int columnCount = tableModel.getColumnCount(); for (int col = 0; col < columnCount; col++) { String s = tableModel.getColumnName(col); if (s.equals(value)) return col; } } return -1; }
From source file:org.yccheok.jstock.gui.JTableUtilities.java
/** * Sets the editor/renderer for Date objects to provided JTable, for the specified column. * @param table JTable to set up/* www. jav a2s . c o m*/ * @param row Column to apply */ public static void setDateEditorAndRendererForRow(JTable table, int row) { final TableColumn column = table.getColumnModel().getColumn(row); // SwingX's. Pretty but buggy. //column.setCellEditor(new DatePickerCellEditor()); column.setCellEditor(new DateFieldTableEditor()); final DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT); column.setCellRenderer(new DateRendererDecoratorEx(column.getCellRenderer(), format)); }
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; }//from w w w.j a va 2 s. com 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); }
From source file:pipeline.parameter_cell_views.CurveEditor.java
@SuppressWarnings("unchecked") @Override//from w w w.j ava2s. c o m protected Component getRendererOrEditorComponent(JTable table, @NonNull Object value, boolean isSelected, boolean hasFocus, int row, int column, boolean rendererCalled) { if (table != null) { Dimension d = getPreferredSize(); d.width = table.getColumnModel().getColumn(column).getWidth(); setSize(d); } if (currentParameter != null) { currentParameter.removeListener(this); } currentParameter = (SplineParameter) value; currentParameter.addGUIListener(this); splineEditor.setCurvePoints((ArrayList<Point2D>) ((Object[]) currentParameter.getValue())[0]); splineEditor.setControlPoints((ArrayList<Point2D>) ((Object[]) currentParameter.getValue())[1]); silenceUpdate = true; evenTableRow = (row % 2 == 0); setOpaque(true); if (evenTableRow) { this.setBackground(Utils.COLOR_FOR_EVEN_ROWS); } else this.setBackground(Utils.COLOR_FOR_ODD_ROWS); updateDisplay(); if (table != null) { int height_wanted = (int) getPreferredSize().getHeight(); if (height_wanted > table.getRowHeight(row)) table.setRowHeight(row, height_wanted); } silenceUpdate = false; return this; }
From source file:pipeline.parameter_cell_views.FloatSlider.java
@SuppressWarnings("unused") @Override/*from w w w. ja va 2s . com*/ public Component getRendererOrEditorComponent(JTable table, @NonNull Object value, boolean isSelected, boolean hasFocus, int row, int column, boolean rendererCalled) { if (table != null) { Dimension d = getPreferredSize(); d.width = table.getColumnModel().getColumn(column).getWidth(); setSize(d); } if (currentParameter != null) { currentParameter.removeListener(this); } currentParameter = (FloatParameter) value; /*if (value == null) { slider.setEnabled(true); textMinimum.setEditable(true); textMaximum.setEditable(true); currentTextValue.setEditable(true); return this; }*/ currentParameter.addGUIListener(this); currentParameter.validateRange(); silenceUpdate = true; evenTableRow = (row % 2 == 0); setOpaque(true); if (evenTableRow) this.setBackground(Utils.COLOR_FOR_EVEN_ROWS); else this.setBackground(Utils.COLOR_FOR_ODD_ROWS); if (true) {// rendererCalled GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; // For some strange reason, the slider doesn't get updated properly upon resizes // (only in the renderer, not the editor) // workaround is to remove it and re-create it remove(slider); readInParameterValues(); slider = new JSlider((int) (minimum * 100f), (int) (maximum * 100f), (int) (currentValue * 100f)); c.gridx = 0; c.gridy = 0; c.weighty = 1.0; c.weightx = 1.0; c.gridwidth = 3; add(slider, c); slider.addChangeListener(new sliderListener()); } else { if (table != null) slider.setBounds(table.getCellRect(row, column, false)); slider.updateUI(); } updateDisplay(); if (table != null) { int height_wanted = (int) getPreferredSize().getHeight(); if (height_wanted > table.getRowHeight(row)) table.setRowHeight(row, height_wanted); } silenceUpdate = false; return this; }
From source file:pl.edu.agh.lib.FileInfo.java
public void columnBacklight(PermissionType permissionType, Boolean deselected, JTable aclList, List<Entity> entities) { int column = 0; switch (permissionType) { case READ:// w ww . java 2 s. co m column = 2; break; case WRITE: column = 3; break; case EXECUTE: column = 4; break; } if (column != 0) { for (Entity entity : entities) { aclList.getColumnModel().getColumn(column).setCellRenderer(new MaskCellRenderer(deselected)); } aclList.updateUI(); } }
From source file:utils.ZTransform.java
@Override public void actionPerformed(ActionEvent e) { List<CMatrix> loadedCMatrices = CoolMapMaster.getLoadedCMatrices(); if (loadedCMatrices == null || loadedCMatrices.isEmpty()) { Messenger.showWarningMessage("No datasets were imported.", "No data"); return;/* w w w . ja va2 s. c om*/ } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JTable table = new JTable(); DefaultTableModel defaultTableModel = Utils.getDefaultTableModel(); table.setModel(defaultTableModel); table.getColumnModel().removeColumn(table.getColumnModel().getColumn(0)); table.getTableHeader().setReorderingAllowed(false); int returnVal = JOptionPane.showConfirmDialog(CoolMapMaster.getCMainFrame(), new JScrollPane(table), "Select data", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (returnVal == JOptionPane.OK_OPTION) { int[] selectedRows = table.getSelectedRows(); ArrayList<CMatrix> selectedMatrices = new ArrayList<CMatrix>(); for (int row : selectedRows) { int index = table.convertRowIndexToModel(row); try { String ID = table.getModel().getValueAt(index, 0).toString(); CMatrix mx = CoolMapMaster.getCMatrixByID(ID); if (mx != null) { selectedMatrices.add(mx); } } catch (Exception e) { } } //do createZTransform(selectedMatrices); } } }); }
From source file:VGL.SummaryChartUI.java
private void updateDisplay() { //find out which buttons have been selected ArrayList<Integer> selectedTraits = new ArrayList<Integer>(); for (int i = 0; i < manager.getTraitSet().length; i++) { if (traitCheckBoxes[i].isSelected()) { selectedTraits.add(i);//ww w . ja v a 2 s. c om } } PhenotypeCount[] result = manager.calculateTotals(selectedTraits, sexCheckBox.isSelected()); String[] columnHeadings = { Messages.getInstance().getString("VGLII.Phenotype"), Messages.getInstance().getString("VGLII.Observed"), Messages.getInstance().getString("VGLII.Expected") }; data = new Object[result.length][3]; for (int i = 0; i < result.length; i++) { data[i][0] = Messages.getInstance().translateLongPhenotypeName(result[i].getPhenotype()); data[i][1] = result[i].getCount(); data[i][2] = ""; } //if none selected, the "phenotype" is "organism" if ((selectedTraits.size() == 0) && !sexCheckBox.isSelected()) data[0][0] = Messages.getInstance().getString("VGLII.Organism"); // set width of columns sensibly - find longest one int maxPhenoStringLength = 0; for (int i = 0; i < result.length; i++) { if (data[i][0].toString().length() > maxPhenoStringLength) maxPhenoStringLength = data[i][0].toString().length(); } int phenoStringWidth = maxPhenoStringLength * 8; JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); JTable table = new JTable(new SummaryDataTableModel(data, columnHeadings)) { //Implement table header tool tips. protected JTableHeader createDefaultTableHeader() { return new JTableHeader(columnModel) { public String getToolTipText(MouseEvent e) { String tip = null; java.awt.Point p = e.getPoint(); int index = columnModel.getColumnIndexAtX(p.x); int realIndex = columnModel.getColumn(index).getModelIndex(); return columnToolTips[realIndex]; } }; } }; table.setGridColor(Color.BLACK); table.setShowGrid(true); table.getColumnModel().getColumn(0).setPreferredWidth(phenoStringWidth); table.getModel().addTableModelListener(this); panel.add(table.getTableHeader()); panel.add(table); resultPanel.removeAll(); resultPanel.add(panel); resultPanel.revalidate(); repaint(); }