List of usage examples for javax.swing JTable getColumnModel
public TableColumnModel getColumnModel()
From source file:org.yccheok.jstock.gui.JTableUtilities.java
public static void makeTableColumnWidthFit(JTable jTable, int col, int margin, boolean locking) { // strategy - get max width for cells in column and // make that the preferred width TableColumnModel columnModel = jTable.getColumnModel(); int maxwidth = 0; for (int row = 0; row < jTable.getRowCount(); row++) { TableCellRenderer rend = jTable.getCellRenderer(row, col); Object value = jTable.getValueAt(row, col); Component comp = rend.getTableCellRendererComponent(jTable, value, false, false, row, col); maxwidth = Math.max(comp.getPreferredSize().width + margin, maxwidth); } // for row//from w w w . j ava 2 s . c o m TableColumn column = columnModel.getColumn(col); TableCellRenderer headerRenderer = column.getHeaderRenderer(); if (headerRenderer == null) { headerRenderer = jTable.getTableHeader().getDefaultRenderer(); } Object headerValue = column.getHeaderValue(); Component headerComp = headerRenderer.getTableCellRendererComponent(jTable, headerValue, false, false, 0, col); maxwidth = Math.max(maxwidth, headerComp.getPreferredSize().width + margin); column.setPreferredWidth(maxwidth); if (locking) { // User will not able to adjust the width manually. column.setMinWidth(maxwidth); column.setMaxWidth(maxwidth); } }
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/* w w w .jav a 2s .com*/ * @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 www .ja v a 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 a v a2s . 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//w ww . j a va 2 s . 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:/*from w w w . j a v a2s .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:qic.ui.QicFrame.java
public QicFrame(Main main, String query) { super("QIC Search - Simple GUI"); setLayout(new BorderLayout(5, 5)); RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60); textArea.setText("Enter a command in the textfield then press Enter.."); textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON); textArea.setCodeFoldingEnabled(true); RTextScrollPane sp = new RTextScrollPane(textArea); JTextField searchTf = new JTextField(100); JButton runBtn = new JButton("Run"); JPanel northPanel = new JPanel(); northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.X_AXIS)); northPanel.add(searchTf);//from w ww .j av a 2 s . c o m northPanel.add(runBtn); getContentPane().add(northPanel, BorderLayout.NORTH); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setSize(screenSize.width - 50, screenSize.height - 50); setLocationRelativeTo(null); searchTf.setText("search bo tmpsc "); if (query != null) { searchTf.setText(query); } JTable table = new JTable(); table.setDefaultRenderer(List.class, new MultiLineTableCellRenderer()); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab("Table", new JScrollPane(table)); tabbedPane.addTab("JSON", new JScrollPane(sp)); BeanPropertyTableModel<SearchResultItem> model = new BeanPropertyTableModel<>(SearchResultItem.class); model.setOrderedProperties(asList("id", "buyout", "item", "seller", "reqs", "mods", "q", "APS", "PDPS", "EDPS", "DPS", "ele", "phys", "ar", "ev", "ES", "blk", "crit", "lvl")); table.setModel(model); setColumnWidths(table.getColumnModel(), asList(1, 15, 280, 230, 50, 420)); getContentPane().add(tabbedPane, BorderLayout.CENTER); ActionListener runCommand = e -> { String tfText = searchTf.getText(); Worker<Command> pathNotesWorker = new Worker<Command>(() -> runQuery(main, tfText), command -> { String json = command.toJson(); textArea.setText(json); model.setData(command.itemResults); }, ex -> { String stackTrace = ExceptionUtils.getStackTrace(ex); textArea.setText(stackTrace); showError(ex); }); pathNotesWorker.execute(); }; searchTf.addActionListener(runCommand); runBtn.addActionListener(runCommand); table.getSelectionModel().addListSelectionListener(e -> { if (e.getValueIsAdjusting()) { int selectedRow = table.getSelectedRow(); if (selectedRow > -1) { SearchResultItem searchResultItem = model.getData().get(selectedRow); SwingUtil.copyToClipboard(searchResultItem.wtb()); } } }); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); }
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;//from www . jav a 2 s.com } 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);//www .j av a2s .c o m } } 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(); }
From source file:vista.promocion.DiagPromocion.java
private void configurarTabla(JTable tbl) { JViewport scroll = (JViewport) tbl.getParent(); int ancho = scroll.getWidth(); int anchoColumna = 0; TableColumnModel modeloColumna = tbl.getColumnModel(); TableColumn columnaTabla;//ww w . j av a2 s . c o m for (int i = 0; i < tbl.getColumnCount(); i++) { columnaTabla = modeloColumna.getColumn(i); switch (i) { case 0: anchoColumna = (1 * ancho) / 100; break; case 1: anchoColumna = (20 * ancho) / 100; break; case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: anchoColumna = (5 * ancho) / 100; break; } columnaTabla.setPreferredWidth(anchoColumna); tbl.setColumnModel(modeloColumna); } tbl.getTableHeader().setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10)); tbl.getTableHeader().setBackground(java.awt.Color.WHITE); tbl.getTableHeader().setForeground(Color.BLACK); //Si le queremos cambiar el tamao a la tablita tbl.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10)); }