List of usage examples for javax.swing.table JTableHeader setReorderingAllowed
@BeanProperty(description = "Whether the user can drag column headers to reorder columns.") public void setReorderingAllowed(boolean reorderingAllowed)
From source file:TableSortDemo.java
public TableSortDemo() { super();/* w w w . j a v a 2 s .c om*/ setSize(600, 300); tableModel = new MyTableModel(); getContentPane().add(titleLabel, BorderLayout.NORTH); table.setModel(tableModel); JTableHeader header = table.getTableHeader(); header.setUpdateTableInRealTime(true); header.addMouseListener(tableModel.new ColumnListener(table)); header.setReorderingAllowed(true); JScrollPane ps = new JScrollPane(); ps.getViewport().add(table); getContentPane().add(ps, BorderLayout.CENTER); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:com.compomics.cell_coord.gui.controller.summary.SummaryDataController.java
/** * Initialize main view./*from ww w. j ava 2 s .c om*/ */ private void initSummaryDataPanel() { // create new object summaryDataPanel = new SummaryDataPanel(); // format the tables JTableHeader samplesHeader = summaryDataPanel.getSamplesTable().getTableHeader(); samplesHeader.setBackground(GuiUtils.getHeaderColor()); samplesHeader.setFont(GuiUtils.getHeaderFont()); samplesHeader.setReorderingAllowed(false); JTableHeader tracksHeader = summaryDataPanel.getTracksTable().getTableHeader(); tracksHeader.setBackground(GuiUtils.getHeaderColor()); tracksHeader.setFont(GuiUtils.getHeaderFont()); tracksHeader.setReorderingAllowed(false); JTableHeader trackSpotsHeader = summaryDataPanel.getTrackSpotsTable().getTableHeader(); trackSpotsHeader.setBackground(GuiUtils.getHeaderColor()); trackSpotsHeader.setFont(GuiUtils.getHeaderFont()); trackSpotsHeader.setReorderingAllowed(false); summaryDataPanel.getSamplesTable().setRowSelectionAllowed(true); summaryDataPanel.getSamplesTable().setColumnSelectionAllowed(false); summaryDataPanel.getSamplesTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); summaryDataPanel.getTracksTable().setRowSelectionAllowed(true); summaryDataPanel.getTracksTable().setColumnSelectionAllowed(false); summaryDataPanel.getTracksTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // if you click on a sample, the relative tracks are shown in another table summaryDataPanel.getSamplesTable().getSelectionModel() .addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int selectedRow = summaryDataPanel.getSamplesTable().getSelectedRow(); if (selectedRow != -1) { Sample selectedSample = loadTracksController.getSamples().get(selectedRow); showTracksInTable(selectedSample); } } } }); // if you click on a track, the relative spots are shown in another table summaryDataPanel.getTracksTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { Sample selectedSample = loadTracksController.getSamples() .get(summaryDataPanel.getSamplesTable().getSelectedRow()); int selectedRow = summaryDataPanel.getTracksTable().getSelectedRow(); if (selectedRow != -1) { Track selectedTrack = selectedSample.getTracks().get(selectedRow); showSpotsInTable(selectedTrack); } } } }); // add view to parent controller loadTracksController.getMainFrame().getSummaryDataParentPanel().add(summaryDataPanel, gridBagConstraints); }
From source file:com.compomics.cell_coord.gui.controller.computation.ComputationMainController.java
/** * Initialize some GUI components./*from w w w .j a v a2 s . c om*/ */ private void initMainView() { // format the tables JTableHeader samplesHeader = getMainFrame().getSamplesTable().getTableHeader(); samplesHeader.setBackground(GuiUtils.getHeaderColor()); samplesHeader.setFont(GuiUtils.getHeaderFont()); samplesHeader.setReorderingAllowed(false); JTableHeader tracksHeader = getMainFrame().getTracksTable().getTableHeader(); tracksHeader.setBackground(GuiUtils.getHeaderColor()); tracksHeader.setFont(GuiUtils.getHeaderFont()); tracksHeader.setReorderingAllowed(false); getMainFrame().getSamplesTable().setRowSelectionAllowed(true); getMainFrame().getSamplesTable().setColumnSelectionAllowed(false); getMainFrame().getSamplesTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); getMainFrame().getTracksTable().setRowSelectionAllowed(true); getMainFrame().getTracksTable().setColumnSelectionAllowed(false); getMainFrame().getTracksTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // if you click on a sample, the relative tracks are shown in another table getMainFrame().getSamplesTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int selectedRow = getMainFrame().getSamplesTable().getSelectedRow(); if (selectedRow != -1) { Sample selectedSample = getSamples().get(selectedRow); showTracksInTable(selectedSample); computationDataController.computeSample(selectedSample); // call child controller to show sample data in table computationDataController.showSampleData(selectedSample); // call child controller to plot whatever we need to plot } } } }); // if you click on a track, the relative spots are shown in another table getMainFrame().getTracksTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { Sample selectedSample = getSamples().get(getMainFrame().getSamplesTable().getSelectedRow()); int selectedRow = getMainFrame().getTracksTable().getSelectedRow(); if (selectedRow != -1) { Track selectedTrack = selectedSample.getTracks().get(selectedRow); // call child controller to show track data in table computationDataController.showStepData(selectedTrack); computationDataController.showTrackData(selectedTrack); // call child controller to plot whatever we need to plot computationDataController.plotStepData(selectedTrack); computationDataController.plotTrackData(selectedTrack); } } } }); }
From source file:com.sec.ose.osi.ui.frm.main.manage.AddProjectTableModel.java
public void setColumnView(JTable table) { table.setShowVerticalLines(false);// w w w . j a v a2s.co m table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setColumnSelectionAllowed(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); 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; searchHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ISSELECT), ""); col = cm.getColumn(COL_ISSELECT); col.setHeaderRenderer(searchHeader); }
From source file:ecosim.gui.SummaryPane.java
/** * Private method to build the table pane. * * @return A JLayeredPane containing the table pane. *//* ww w . j av a 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:StocksTable4.java
public StocksTable4() { super("Stocks Table"); setSize(600, 300);/* w w w . ja v a 2 s . co m*/ m_data = new StockTableData(); m_title = new JLabel(m_data.getTitle(), new ImageIcon("money.gif"), SwingConstants.LEFT); m_title.setFont(new Font("TimesRoman", Font.BOLD, 24)); m_title.setForeground(Color.black); getContentPane().add(m_title, BorderLayout.NORTH); m_table = new JTable(); m_table.setAutoCreateColumnsFromModel(false); m_table.setModel(m_data); for (int k = 0; k < StockTableData.m_columns.length; k++) { DefaultTableCellRenderer renderer = new ColoredTableCellRenderer(); renderer.setHorizontalAlignment(StockTableData.m_columns[k].m_alignment); TableColumn column = new TableColumn(k, StockTableData.m_columns[k].m_width, renderer, null); m_table.addColumn(column); } JTableHeader header = m_table.getTableHeader(); header.setUpdateTableInRealTime(true); header.addMouseListener(m_data.new ColumnListener(m_table)); header.setReorderingAllowed(true); JScrollPane ps = new JScrollPane(); ps.getViewport().add(m_table); getContentPane().add(ps, BorderLayout.CENTER); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:com.compomics.cell_coord.gui.controller.computation.ComputationDataController.java
/** * Initialize main view.//from w w w.j ava2 s . c o m */ private void initComputationDataPanel() { // make a new object computationDataPanel = new ComputationDataPanel(); // format the tables JTableHeader header = computationDataPanel.getStepDataTable().getTableHeader(); header.setBackground(GuiUtils.getHeaderColor()); header.setFont(GuiUtils.getHeaderFont()); header.setReorderingAllowed(false); header = computationDataPanel.getSampleDataTable().getTableHeader(); header.setBackground(GuiUtils.getHeaderColor()); header.setFont(GuiUtils.getHeaderFont()); header.setReorderingAllowed(false); header = computationDataPanel.getSampleDataTable().getTableHeader(); header.setBackground(GuiUtils.getHeaderColor()); header.setFont(GuiUtils.getHeaderFont()); header.setReorderingAllowed(false); header = computationDataPanel.getTrackDataTable().getTableHeader(); header.setBackground(GuiUtils.getHeaderColor()); header.setFont(GuiUtils.getHeaderFont()); header.setReorderingAllowed(false); computationDataPanel.getStepDataTable().setRowSelectionAllowed(true); computationDataPanel.getStepDataTable().setColumnSelectionAllowed(false); computationDataPanel.getStepDataTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); computationDataPanel.getStepDataTable().setRowSelectionAllowed(true); computationDataPanel.getStepDataTable().setColumnSelectionAllowed(false); computationDataPanel.getStepDataTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // add component to main container computationMainController.getMainFrame().getComputationDataParentPanel().add(computationDataPanel, gridBagConstraints); }
From source file:com.sec.ose.osi.ui.frm.main.manage.ManagedProjectTableModel.java
public void setColumnType(JTable table) { table.setShowVerticalLines(false);//from w ww . ja va 2s.co 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:com.compomics.cell_coord.gui.controller.load.LoadTracksController.java
/** * Initialize the view components.//from ww w . j a v a 2 s . c om */ private void initView() { // create new view loadTracksPanel = new LoadTracksPanel(); // disable the IMPORT FILES button loadTracksPanel.getImportFilesButton().setEnabled(false); // initialize the flag to keep track of importing isImported = false; // populate the combobox with available file formats // note: these are annoatated as spring beans Set<String> parsers = TrackFileParserFactory.getInstance().getParserBeanNames(); for (String parser : parsers) { loadTracksPanel.getFileFormatComboBox().addItem(parser); } // format the table JTableHeader tracksTableHeader = loadTracksPanel.getTracksTable().getTableHeader(); tracksTableHeader.setBackground(GuiUtils.getHeaderColor()); tracksTableHeader.setFont(GuiUtils.getHeaderFont()); tracksTableHeader.setReorderingAllowed(false); /** * Action Listeners. */ // load directory loadTracksPanel.getLoadDirectoryButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (directory == null) { chooseDirectoryAndLoadData(); } else { // otherwise we ask the user if they want to reload the directory Object[] options = { "Load a different directory", "Cancel" }; int showOptionDialog = JOptionPane.showOptionDialog(null, "It seems a directory was already loaded.\nWhat do you want to do?", "", JOptionPane.CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); switch (showOptionDialog) { case 0: // load a different directory: // reset the model of the directory tree DefaultTreeModel model = (DefaultTreeModel) loadTracksPanel.getDirectoryTree().getModel(); DefaultMutableTreeNode rootNote = (DefaultMutableTreeNode) model.getRoot(); rootNote.removeAllChildren(); model.reload(); chooseDirectoryAndLoadData(); loadTracksPanel.getChosenDirectoryTextArea().setText(directory.getAbsolutePath()); break; // cancel: do nothing } } } }); // import the selected files in the tree loadTracksPanel.getImportFilesButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // check if an import already took place if (!isImported) { // get the selected file(s) from the JTree TreePath[] selectionPaths = loadTracksPanel.getDirectoryTree().getSelectionPaths(); if (selectionPaths != null && selectionPaths.length != 0) { // at least a file was selected -- proceed with the import importFiles(); isImported = true; cellCoordController.showMessage(selectionPaths.length + " file(s) successfully imported!", "success loading", JOptionPane.INFORMATION_MESSAGE); // do basic computations preprocess(); // go to child controllers and show samples in the tables summaryDataController.showSamplesInTable(); computationMainController.showSamplesInTable(); // proceed with next step in the plugin cellCoordController.getCellCoordFrame().getNextButton().setEnabled(true); } else { // inform the user that no file was selected! cellCoordController.showMessage("You have to select at least one file!", "no files selected", JOptionPane.WARNING_MESSAGE); } } else { // an import already took place: ask for user input Object[] options = { "Load other file(s)", "Cancel" }; int showOptionDialog = JOptionPane.showOptionDialog(loadTracksPanel, "It seems some files were already loaded.\nWhat do you want to do?", "", JOptionPane.CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); switch (showOptionDialog) { case 0: // load other files // clear the sample list samples.clear(); // clear the track spot list trackSpotsBindingList.clear(); // clear the selection in the JTree loadTracksPanel.getDirectoryTree().clearSelection(); isImported = false; // inform the user they need to select other files JOptionPane.showMessageDialog(loadTracksPanel, "Please select other files", "", JOptionPane.INFORMATION_MESSAGE); break; // cancel: do nothing } } } }); // add view to parent component cellCoordController.getCellCoordFrame().getLoadTracksParentPanel().add(loadTracksPanel, gridBagConstraints); }
From source file:StocksTable5.java
public StocksTable5() { super("Stocks Table"); setSize(600, 300);//from w w w.j a v a 2 s . c om m_data = new StockTableData(); m_title = new JLabel(m_data.getTitle(), new ImageIcon("money.gif"), SwingConstants.LEFT); m_title.setFont(new Font("TimesRoman", Font.BOLD, 24)); m_title.setForeground(Color.black); getContentPane().add(m_title, BorderLayout.NORTH); m_table = new JTable(); m_table.setAutoCreateColumnsFromModel(false); m_table.setModel(m_data); for (int k = 0; k < StockTableData.m_columns.length; k++) { DefaultTableCellRenderer renderer = new ColoredTableCellRenderer(); renderer.setHorizontalAlignment(StockTableData.m_columns[k].m_alignment); TableColumn column = new TableColumn(k, StockTableData.m_columns[k].m_width, renderer, null); m_table.addColumn(column); } JTableHeader header = m_table.getTableHeader(); header.setUpdateTableInRealTime(true); header.addMouseListener(m_data.new ColumnListener(m_table)); header.setReorderingAllowed(true); JScrollPane ps = new JScrollPane(); ps.getViewport().add(m_table); getContentPane().add(ps, BorderLayout.CENTER); JMenuBar menuBar = createMenuBar(); setJMenuBar(menuBar); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }