List of usage examples for javax.swing JTable getTableHeader
public JTableHeader getTableHeader()
tableHeader
used by this JTable
. From source file:ecosim.gui.SummaryPane.java
/** * Private method to build the table pane. * * @return A JLayeredPane containing the table pane. */// ww w .j a va 2 s . c o 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:logdruid.ui.table.StatRecordingEditorTable.java
private void initColumnSizes(JTable theTable) { MyTableModel model = (MyTableModel) theTable.getModel(); TableColumn column = null;/*from w w w. j a v a2 s.c o m*/ Component comp = null; int headerWidth = 0; int cellWidth = 0; // Object[] longValues = model.longValues; TableCellRenderer headerRenderer = theTable.getTableHeader().getDefaultRenderer(); for (int i = 0; i < 6; i++) { column = theTable.getColumnModel().getColumn(i); comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; cellWidth = comp.getPreferredSize().width; if (DEBUG) { logger.info("Initializing width of column " + i + ". " + "headerWidth = " + headerWidth + "; cellWidth = " + cellWidth); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
From source file:com.sec.ose.osi.ui.frm.main.manage.AddProjectTableModel.java
public void checkSelectAll(JTable table) { boolean isAllChecked = false; int select_cnt = 0; for (OSIProjectInfo pi : projectsListInfo) { if (pi.isManaged()) select_cnt++;// w w w . ja v a2s . c o m } if (select_cnt == projectsListInfo.size()) { isAllChecked = true; } isHeaderWork = true; searchHeader.setSelected(isAllChecked); ((JTableHeader) table.getTableHeader()).repaint(); isHeaderWork = false; }
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);/*from w ww . jav a 2 s. co 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:logdruid.ui.mainpanel.MetadataRecordingSelectorPanel.java
private void initColumnSizes(JTable theTable) { MyTableModel model = (MyTableModel) theTable.getModel(); TableColumn column = null;//from www. ja v a2 s . co m Component comp = null; int headerWidth = 0; int cellWidth = 0; // Object[] longValues = model.longValues; TableCellRenderer headerRenderer = theTable.getTableHeader().getDefaultRenderer(); for (int i = 0; i < 4; i++) { column = theTable.getColumnModel().getColumn(i); comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; cellWidth = comp.getPreferredSize().width; column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
From source file:TableSorter.java
/** * @param table1//ww w.j ava 2 s. c o m */ public void addMouseListenerToHeaderInTable(JTable table1) { table1.setColumnSelectionAllowed(false); setTableHeader(table1.getTableHeader()); }
From source file:com.willwinder.universalgcodesender.uielements.panels.ControllerProcessorSettingsPanel.java
private JTable initCustomRemoverTable(JTable table) { final String[] columnNames = { Localization.getString("settings.processors.enabled"), Localization.getString("PatternRemover") }; final Class[] columnTypes = { Boolean.class, String.class }; DefaultTableModel model = new DefaultTableModel(null, columnNames) { @Override/*w ww . j a va 2s. co m*/ public Class<?> getColumnClass(int idx) { return columnTypes[idx]; } }; table.setModel(model); table.getTableHeader().setReorderingAllowed(false); table.getModel().addTableModelListener((TableModelEvent e) -> change()); return table; }
From source file:com.sec.ose.osi.ui.frm.main.manage.ManagedProjectTableModel.java
public void setColumnType(JTable table) { table.setShowVerticalLines(false);/*from w w w . j a v a 2s . c o m*/ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setRowHeight(30); JTableHeader header = table.getTableHeader(); header.setPreferredSize(new java.awt.Dimension(table.getTableHeader().getWidth(), 30)); header.setFont(new Font("Arial", Font.BOLD, 12)); header.setReorderingAllowed(false); TableColumnModel cm = table.getColumnModel(); TableColumn col = null; analyzeHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ANALYZE_TARGET), "Analyze Target"); col = cm.getColumn(COL_ANALYZE_TARGET); col.setHeaderRenderer(analyzeHeader); JCheckBox chkbox = new JCheckBox(); chkbox.setBackground(Color.white); chkbox.setHorizontalAlignment(JLabel.CENTER); col.setCellRenderer(new DefaultTableCellRenderer() { private static final long serialVersionUID = 1L; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { ManagedProjectTableModel model = (ManagedProjectTableModel) table.getModel(); String sPrjName = (String) table.getValueAt(row, ManagedProjectTableModel.COL_PROJECT_NAME); OSIProjectInfo item = model.getProjectInfo(sPrjName); JCheckBox chkbox = new JCheckBox(); chkbox.setSelected(((Boolean) value).booleanValue()); if (item != null) { chkbox.setEnabled(item.isLocationValid()); } chkbox.setHorizontalAlignment(JLabel.CENTER); chkbox.setBackground(Color.white); return (Component) chkbox; } }); col.setCellEditor(new DefaultCellEditor(chkbox)); col = cm.getColumn(COL_ANALYZE_STATUS); col.setCellRenderer(new StatusIconCellRenderer()); col = cm.getColumn(COL_SOURCE_LOCATION); col.setCellRenderer(new FileBrowseCellRenderer()); col.setCellEditor(new FileBrowseCellEditor()); }
From source file:net.pandoragames.far.ui.swing.FileListPanel.java
private void init(SwingConfig config, ComponentRepository componentRepository) { this.setLayout(new BorderLayout()); this.setBorder( BorderFactory.createEmptyBorder(0, SwingConfig.PADDING, SwingConfig.PADDING, SwingConfig.PADDING)); tableModel = componentRepository.getTableModel(); componentRepository.getResetDispatcher().addResetable(tableModel); componentRepository.getSearchBaseListener().addResetable(tableModel); componentRepository.getUndoListener().setTableModel(tableModel); JTable fileListTable = componentRepository.getFileSetTable(); int totalWidth = fileListTable.getPreferredSize().width; fileListTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); fileListTable.setColumnSelectionAllowed(true); fileListTable.getTableHeader().addMouseListener(new TableHeaderMouseListener()); fileListTable.getTableHeader().getColumnModel().getColumn(0) .setHeaderRenderer(new TableHeaderCheckBoxColumnRenderer()); fileListPopupMenu = new FileListPopupMenu(fileListTable, tableModel, componentRepository, config); fileListTable.setComponentPopupMenu(fileListPopupMenu); fileListTable.addMouseListener(new FileViewOpener(fileListTable, componentRepository.getRootWindow(), config, componentRepository)); fileListTable.getColumnModel().getColumn(0).setPreferredWidth(20); fileListTable.getColumnModel().getColumn(0).setMaxWidth(20); fileListTable.getColumnModel().getColumn(1).setCellRenderer(new TargetFileListTableCellRenderer()); fileListTable.getColumnModel().getColumn(1).setPreferredWidth(2 * totalWidth / 5); fileListTable.getColumnModel().getColumn(2).setCellRenderer(new PathColumnRenderer()); fileListTable.getColumnModel().getColumn(3).setCellRenderer(new InfoColumnRenderer(config)); JScrollPane scrollPane = new JScrollPane(fileListTable); this.add(scrollPane, BorderLayout.CENTER); SelectCounter fileCounter = new SelectCounter(); fileCounter.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING)); fileCounter.setForeground(Color.GRAY); ErrorCounter errorCounter = new ErrorCounter(); errorCounter.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING)); JPanel counterLine = new JPanel(); counterLine.setLayout(new BorderLayout()); counterLine.add(fileCounter, BorderLayout.WEST); counterLine.add(errorCounter, BorderLayout.EAST); JProgressBar progressBar = new JProgressBar(); progressBar.setEnabled(false);/*from w w w . ja v a 2 s . com*/ progressBar.setMaximumSize(new Dimension(100, 20)); progressBar.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING)); componentRepository.getProgressBarUpdater().setProgressBar(progressBar); JPanel progressBarPanel = new JPanel(); progressBarPanel.add(progressBar); counterLine.add(progressBarPanel, BorderLayout.CENTER); counterLine.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); this.add(counterLine, BorderLayout.SOUTH); tableModel.addTableModelListener(new ColumnCountListener(fileCounter)); tableModel.addTableModelListener(errorCounter); componentRepository.getResetDispatcher().addResetable(fileCounter); componentRepository.getSearchBaseListener().addResetable(fileCounter); componentRepository.getOperationCallBackListener().addComponentStartReseted(fileCounter, OperationType.FIND); componentRepository.getResetDispatcher().addResetable(errorCounter); componentRepository.getSearchBaseListener().addResetable(errorCounter); viewAction = new ActionView(componentRepository, config); }
From source file:logdruid.ui.RecordingList.java
private void initColumnSizes(JTable theTable) { MyTableModel2 model = (MyTableModel2) theTable.getModel(); TableColumn column = null;// w w w .jav a 2 s. co m Component comp = null; int headerWidth = 0; int cellWidth = 0; // Object[] longValues = model.longValues; TableCellRenderer headerRenderer = theTable.getTableHeader().getDefaultRenderer(); for (int i = 0; i < 4; i++) { column = theTable.getColumnModel().getColumn(i); comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; cellWidth = comp.getPreferredSize().width; column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }