List of usage examples for javax.swing.table TableColumnModel getColumn
public TableColumn getColumn(int columnIndex);
TableColumn
object for the column at columnIndex
. From source file:GeMSE.GS.Analysis.Stats.OneSampleCovariancePanel.java
public void ResizeColumnWidth(JTable table) { final TableColumnModel columnModel = table.getColumnModel(); for (int column = 0; column < table.getColumnCount(); column++) { int width = 50; // Min width TableColumn tableColumn = columnModel.getColumn(column); TableCellRenderer renderer = tableColumn.getHeaderRenderer(); if (renderer == null) renderer = table.getTableHeader().getDefaultRenderer(); Component component = renderer.getTableCellRendererComponent(table, tableColumn.getHeaderValue(), false, false, -1, column);/* w w w. j a va 2 s. c o m*/ width = Math.max(component.getPreferredSize().width + 5, width); for (int row = 0; row < table.getRowCount(); row++) { renderer = table.getCellRenderer(row, column); Component comp = table.prepareRenderer(renderer, row, column); width = Math.max(comp.getPreferredSize().width + 5, width); } if (width > 400) width = 400; columnModel.getColumn(column).setPreferredWidth(width); } }
From source file:edu.ucla.stat.SOCR.chart.SuperYIntervalChart.java
public void setXLabel(String xLabel) { domainLabel = xLabel;/* w w w. j av a2s. c o m*/ TableColumnModel columnModel = dataTable.getColumnModel(); columnModel.getColumn(0).setHeaderValue(domainLabel); dataTable.setTableHeader(new EditableHeader(columnModel)); }
From source file:edu.ucla.stat.SOCR.chart.SuperYIntervalChart.java
public void setYLabel(String yLabel) { rangeLabel = yLabel;/*from w ww . j a va 2s . co m*/ TableColumnModel columnModel = dataTable.getColumnModel(); columnModel.getColumn(1).setHeaderValue(rangeLabel); dataTable.setTableHeader(new EditableHeader(columnModel)); }
From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart_vertical.java
public void setXLabel(String xLabel) { domainLabel = xLabel;// w w w. j a va 2 s .com TableColumnModel columnModel = dataTable.getColumnModel(); columnModel.getColumn(0).setHeaderValue(domainLabel); dataTable.setTableHeader(new EditableHeader(columnModel)); }
From source file:fxts.stations.util.preferences.PreferencesSheetPanel.java
/** * init table// ww w. j a v a 2 s . c o m */ public void initTable() { int width = -1; TableColumnModel columnModel = mTable.getColumnModel(); if (columnModel.getColumnCount() > 1) { width = columnModel.getColumn(0).getPreferredWidth(); } mTableModel.init(); mTableModel.fireTableStructureChanged(); if (width >= 0) { columnModel = mTable.getColumnModel(); columnModel.getColumn(0).setPreferredWidth(width); } }
From source file:com.sec.ose.osi.ui.frm.main.manage.ManagedProjectTableModel.java
public void setColumnWidth(JTable table) { TableColumnModel cm = table.getColumnModel(); col_width = 0;/* w w w . j a v a 2 s.c o m*/ for (int i = 0; i < columnWidth.length; i++) { cm.getColumn(i).setPreferredWidth(columnWidth[i]); col_width += columnWidth[i]; } }
From source file:edu.ucla.stat.SOCR.chart.SuperYIntervalChartA.java
public void setYLabel(String yLabel) { rangeLabel = yLabel;/* ww w . ja v a2 s . c o m*/ TableColumnModel columnModel = dataTable.getColumnModel(); columnModel.getColumn(1).setHeaderValue(rangeLabel + " lower"); columnModel.getColumn(2).setHeaderValue(rangeLabel + " upper"); dataTable.setTableHeader(new EditableHeader(columnModel)); }
From source file:ecosim.gui.SummaryPane.java
/** * Private method to build the table pane. * * @return A JLayeredPane containing the table pane. *//* w ww .j a v a 2 s . co m*/ private JLayeredPane makeTablePane() { String[] columnNames = { "", "Estimate", "Hillclimbing", "Low", "High" }; Integer[] columnWidths = { 250, 60, 60, 60, 60 }; Object[][] rowData = { { "Number of putative ecotypes (npop)", null, null, null, null }, { "Rate of ecotype formation (omega)", null, null, null, null }, { "Rate of periodic selection (sigma)", null, null, null, null } }; final JLayeredPane pane = new JLayeredPane(); final JTable table = new JTable(rowData, columnNames) { public boolean isCellEditable(int row, int column) { return false; } }; final JTableHeader header = table.getTableHeader(); pane.setLayout(new BorderLayout()); header.setReorderingAllowed(false); TableColumnModel cm = table.getColumnModel(); for (int i = 0; i < columnWidths.length; i++) { TableColumn column = cm.getColumn(i); column.setMinWidth(columnWidths[i]); if (i == 0) { column.setCellRenderer(new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); cell.setBackground(header.getBackground()); cell.setForeground(header.getForeground()); return cell; } }); } } pane.add(table.getTableHeader(), "North"); pane.add(table, "Center"); // Watch for changes to the Summary object. summary.addObserver(new Observer() { public void update(Observable o, Object obj) { Summary s = (Summary) obj; ParameterEstimate estimate = s.getEstimate(); ParameterSet hillclimbing = s.getHillclimbing(); ParameterSet[] ci = s.getConfidenceInterval(); if (estimate != null) { ParameterSet e = estimate.getResult(); table.setValueAt(e.getNpop(), 0, 1); table.setValueAt(String.format("%.4f", e.getOmega()), 1, 1); table.setValueAt(String.format("%.4f", e.getSigma()), 2, 1); } if (hillclimbing != null) { table.setValueAt(hillclimbing.getNpop(), 0, 2); table.setValueAt(String.format("%.4f", hillclimbing.getOmega()), 1, 2); table.setValueAt(String.format("%.4f", hillclimbing.getSigma()), 2, 2); } if (ci[0].getNpop() != null) { table.setValueAt(ci[0].getNpop(), 0, 3); table.setValueAt(ci[1].getNpop(), 0, 4); } if (ci[1].getOmega() != null) { table.setValueAt(String.format("%.4f", ci[0].getOmega()), 1, 3); String fmt = "%.4f"; if (ci[1].getOmega() > 10.0D) { fmt = "%.1f"; } else if (ci[1].getOmega() > 1.0D) { fmt = "%.2f"; } table.setValueAt(String.format(fmt, ci[1].getOmega()), 1, 4); } if (ci[1].getSigma() != null) { table.setValueAt(String.format("%.4f", ci[0].getSigma()), 2, 3); if (ci[1].getSigma() > 100.0D - MasterVariables.EPSILON) { table.setValueAt("100", 2, 4); } else { String fmt = "%.4f"; if (ci[1].getSigma() > 10.0D) { fmt = "%.1f"; } else if (ci[1].getSigma() > 1.0D) { fmt = "%.2f"; } table.setValueAt(String.format(fmt, ci[1].getSigma()), 2, 4); } } pane.repaint(); } }); return pane; }
From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatMultiplePanel.java
/** * //www .j ava 2s . c o m */ private void setFormatSwitchTblColumnProperties() { // set details of 1st column (field values) TableColumnModel model = formatSwitchTbl.getColumnModel(); TableColumn column = model.getColumn(model.getColumnIndex(FIELD_VALUE_COL)); column.setMinWidth(20); column.setMaxWidth(300); column.setPreferredWidth(70); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(SwingConstants.CENTER); column.setCellRenderer(renderer); // set details of 3rd column (ellipsis buttons) column = model.getColumn(model.getColumnIndex(ELLIPSIS_BUTTON_COL)); column.setCellRenderer(new EditDataObjFormatButtonRenderer()); column.setCellEditor(new EditDataObjFormatButtonEditor(createCheckBox())); column.setMinWidth(20); column.setMaxWidth(20); column.setPreferredWidth(20); }
From source file:net.sf.jabref.importer.ImportCustomizationDialog.java
/** * * @param frame//ww w. j a v a2 s .c o m */ public ImportCustomizationDialog(final JabRefFrame frame) { super(frame, Localization.lang("Manage custom imports"), false); ImportTableModel tableModel = new ImportTableModel(); customImporterTable = new JTable(tableModel); TableColumnModel cm = customImporterTable.getColumnModel(); cm.getColumn(0).setPreferredWidth(COL_0_WIDTH); cm.getColumn(1).setPreferredWidth(COL_1_WIDTH); cm.getColumn(2).setPreferredWidth(COL_2_WIDTH); cm.getColumn(3).setPreferredWidth(COL_3_WIDTH); JScrollPane sp = new JScrollPane(customImporterTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); customImporterTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); customImporterTable.setPreferredScrollableViewportSize(getSize()); if (customImporterTable.getRowCount() > 0) { customImporterTable.setRowSelectionInterval(0, 0); } JButton addFromFolderButton = new JButton(Localization.lang("Add from folder")); addFromFolderButton.addActionListener(e -> { CustomImporter importer = new CustomImporter(); importer.setBasePath(FileDialogs.getNewDir(frame, new File(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)), Collections.emptyList(), Localization.lang("Select Classpath of New Importer"), JFileChooser.CUSTOM_DIALOG, false)); String chosenFileStr = null; if (importer.getBasePath() != null) { chosenFileStr = FileDialogs.getNewFile(frame, importer.getFileFromBasePath(), Collections.singletonList(".class"), Localization.lang("Select new ImportFormat subclass"), JFileChooser.CUSTOM_DIALOG, false); } if (chosenFileStr != null) { try { importer.setClassName(pathToClass(importer.getFileFromBasePath(), new File(chosenFileStr))); importer.setName(importer.getInstance().getFormatName()); importer.setCliId(importer.getInstance().getId()); addOrReplaceImporter(importer); customImporterTable.revalidate(); customImporterTable.repaint(); } catch (Exception exc) { JOptionPane.showMessageDialog(frame, Localization.lang("Could not instantiate %0", chosenFileStr)); } catch (NoClassDefFoundError exc) { JOptionPane.showMessageDialog(frame, Localization.lang( "Could not instantiate %0. Have you chosen the correct package path?", chosenFileStr)); } } }); addFromFolderButton .setToolTipText(Localization.lang("Add a (compiled) custom ImportFormat class from a class path.") + "\n" + Localization.lang("The path need not be on the classpath of JabRef.")); JButton addFromJarButton = new JButton(Localization.lang("Add from jar")); addFromJarButton.addActionListener(e -> { String basePath = FileDialogs.getNewFile(frame, new File(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)), Arrays.asList(".zip", ".jar"), Localization.lang("Select a Zip-archive"), JFileChooser.CUSTOM_DIALOG, false); if (basePath != null) { try (ZipFile zipFile = new ZipFile(new File(basePath), ZipFile.OPEN_READ)) { ZipFileChooser zipFileChooser = new ZipFileChooser(this, zipFile); zipFileChooser.setVisible(true); customImporterTable.revalidate(); customImporterTable.repaint(10); } catch (IOException exc) { LOGGER.info("Could not open Zip-archive.", exc); JOptionPane.showMessageDialog(frame, Localization.lang("Could not open %0", basePath) + "\n" + Localization.lang("Have you chosen the correct package path?")); } catch (NoClassDefFoundError exc) { LOGGER.info("Could not instantiate Zip-archive reader.", exc); JOptionPane.showMessageDialog(frame, Localization.lang("Could not instantiate %0", basePath) + "\n" + Localization.lang("Have you chosen the correct package path?")); } } }); addFromJarButton .setToolTipText(Localization.lang("Add a (compiled) custom ImportFormat class from a Zip-archive.") + "\n" + Localization.lang("The Zip-archive need not be on the classpath of JabRef.")); JButton showDescButton = new JButton(Localization.lang("Show description")); showDescButton.addActionListener(e -> { int row = customImporterTable.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(frame, Localization.lang("Please select an importer.")); } else { CustomImporter importer = ((ImportTableModel) customImporterTable.getModel()).getImporter(row); try { ImportFormat importFormat = importer.getInstance(); JOptionPane.showMessageDialog(frame, importFormat.getDescription()); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException exc) { LOGGER.warn("Could not instantiate importer " + importer.getName(), exc); JOptionPane.showMessageDialog(frame, Localization.lang("Could not instantiate %0 %1", importer.getName() + ":\n", exc.getMessage())); } } }); JButton removeButton = new JButton(Localization.lang("Remove")); removeButton.addActionListener(e -> { int row = customImporterTable.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(frame, Localization.lang("Please select an importer.")); } else { customImporterTable.removeRowSelectionInterval(row, row); Globals.prefs.customImports .remove(((ImportTableModel) customImporterTable.getModel()).getImporter(row)); Globals.IMPORT_FORMAT_READER.resetImportFormats(); customImporterTable.revalidate(); customImporterTable.repaint(); } }); Action closeAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }; JButton closeButton = new JButton(Localization.lang("Close")); closeButton.addActionListener(closeAction); JButton helpButton = new HelpAction(HelpFile.CUSTOM_IMPORTS).getHelpButton(); // Key bindings: JPanel mainPanel = new JPanel(); ActionMap am = mainPanel.getActionMap(); InputMap im = mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", closeAction); mainPanel.setLayout(new BorderLayout()); mainPanel.add(sp, BorderLayout.CENTER); JPanel buttons = new JPanel(); ButtonBarBuilder bb = new ButtonBarBuilder(buttons); buttons.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); bb.addGlue(); bb.addButton(addFromFolderButton); bb.addButton(addFromJarButton); bb.addButton(showDescButton); bb.addButton(removeButton); bb.addButton(closeButton); bb.addUnrelatedGap(); bb.addButton(helpButton); bb.addGlue(); getContentPane().add(mainPanel, BorderLayout.CENTER); getContentPane().add(buttons, BorderLayout.SOUTH); this.setSize(getSize()); pack(); this.setLocationRelativeTo(frame); new FocusRequester(customImporterTable); }