Example usage for javax.swing JTable repaint

List of usage examples for javax.swing JTable repaint

Introduction

In this page you can find the example usage for javax.swing JTable repaint.

Prototype

public void repaint() 

Source Link

Document

Repaints this component.

Usage

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.SingleCellStatisticsController.java

/**
 * Initialize main view.//from   w  ww  .ja v a 2  s.  c om
 */
private void initMainView() {
    // the view is kept in the parent controllers
    AnalysisPanel analysisPanel = singleCellAnalysisController.getAnalysisPanel();
    analysisPanel.getConditionList().setModel(new DefaultListModel());
    // customize tables
    analysisPanel.getStatTable().getTableHeader().setReorderingAllowed(false);
    analysisPanel.getStatTable().getTableHeader().setReorderingAllowed(false);
    analysisPanel.getComparisonTable().setFillsViewportHeight(true);
    analysisPanel.getComparisonTable().setFillsViewportHeight(true);

    // init binding
    groupsBindingList = ObservableCollections.observableList(new ArrayList<SingleCellAnalysisGroup>());
    JListBinding jListBinding = SwingBindings.createJListBinding(AutoBinding.UpdateStrategy.READ_WRITE,
            groupsBindingList, analysisPanel.getAnalysisGroupList());
    bindingGroup.addBinding(jListBinding);

    // fill in combo box
    List<Double> significanceLevels = new ArrayList<>();
    for (SignificanceLevel significanceLevel : SignificanceLevel.values()) {
        significanceLevels.add(significanceLevel.getValue());
    }
    ObservableList<Double> significanceLevelsBindingList = ObservableCollections
            .observableList(significanceLevels);
    JComboBoxBinding jComboBoxBinding = SwingBindings.createJComboBoxBinding(
            AutoBinding.UpdateStrategy.READ_WRITE, significanceLevelsBindingList,
            analysisPanel.getSignLevelComboBox());
    bindingGroup.addBinding(jComboBoxBinding);
    bindingGroup.bind();
    // add the NONE (default) correction method
    // when the none is selected, CellMissy does not correct for multiple hypotheses
    analysisPanel.getCorrectionComboBox().addItem("none");
    // fill in combo box: get all the correction methods from the factory
    Set<String> correctionBeanNames = MultipleComparisonsCorrectionFactory.getInstance()
            .getCorrectionBeanNames();
    correctionBeanNames.stream().forEach((correctionBeanName) -> {
        analysisPanel.getCorrectionComboBox().addItem(correctionBeanName);
    });
    // do the same for the statistical tests
    Set<String> statisticsCalculatorBeanNames = StatisticsTestFactory.getInstance()
            .getStatisticsCalculatorBeanNames();
    statisticsCalculatorBeanNames.stream().forEach((testName) -> {
        analysisPanel.getStatTestComboBox().addItem(testName);
    });
    //significance level to 0.05
    analysisPanel.getSignLevelComboBox().setSelectedIndex(1);
    // add parameters to perform analysis on
    analysisPanel.getParameterComboBox().addItem("cell speed");
    analysisPanel.getParameterComboBox().addItem("cell direct");

    /**
     * Add a group to analysis
     */
    analysisPanel.getAddGroupButton().addActionListener((ActionEvent e) -> {
        // from selected conditions make a new group and add it to the list
        addGroupToAnalysis();
    });

    /**
     * Remove a Group from analysis
     */
    analysisPanel.getRemoveGroupButton().addActionListener((ActionEvent e) -> {
        // remove the selected group from list
        removeGroupFromAnalysis();
    });
    /**
     * Execute a Mann Whitney Test on selected Analysis Group
     */
    analysisPanel.getPerformStatButton().addActionListener((ActionEvent e) -> {
        int selectedIndex = analysisPanel.getAnalysisGroupList().getSelectedIndex();
        String statisticalTestName = analysisPanel.getStatTestComboBox().getSelectedItem().toString();
        String param = analysisPanel.getParameterComboBox().getSelectedItem().toString();
        // check that an analysis group is being selected
        if (selectedIndex != -1) {
            SingleCellAnalysisGroup selectedGroup = groupsBindingList.get(selectedIndex);
            // compute statistics
            computeStatistics(selectedGroup, statisticalTestName, param);
            // show statistics in tables
            showSummary(selectedGroup);
            // set the correction combobox to the one already chosen
            analysisPanel.getCorrectionComboBox().setSelectedItem(selectedGroup.getCorrectionMethodName());
            if (selectedGroup.getCorrectionMethodName().equals("none")) {
                // by default show p-values without adjustment
                showPValues(selectedGroup, false);
            } else {
                // show p values with adjustement
                showPValues(selectedGroup, true);
            }
        } else {
            // ask user to select a group
            singleCellAnalysisController.showMessage("Please select a group to perform analysis on.",
                    "You must select a group first", JOptionPane.INFORMATION_MESSAGE);
        }
    });

    /**
     * Refresh p value table with current selected significance of level
     */
    analysisPanel.getSignLevelComboBox().addActionListener((ActionEvent e) -> {
        if (analysisPanel.getSignLevelComboBox().getSelectedIndex() != -1) {
            String statisticalTest = analysisPanel.getStatTestComboBox().getSelectedItem().toString();
            Double selectedSignLevel = (Double) analysisPanel.getSignLevelComboBox().getSelectedItem();
            SingleCellAnalysisGroup selectedGroup = groupsBindingList
                    .get(analysisPanel.getAnalysisGroupList().getSelectedIndex());
            boolean isAdjusted = !selectedGroup.getCorrectionMethodName().equals("none");
            singleCellStatisticsAnalyzer.detectSignificance(selectedGroup, statisticalTest, selectedSignLevel,
                    isAdjusted);
            boolean[][] significances = selectedGroup.getSignificances();
            JTable pValuesTable = analysisPanel.getComparisonTable();
            for (int i = 1; i < pValuesTable.getColumnCount(); i++) {
                pValuesTable.getColumnModel().getColumn(i)
                        .setCellRenderer(new PValuesTableRenderer(new DecimalFormat("#.####"), significances));
            }
            pValuesTable.repaint();
        }
    });

    /**
     * Apply correction for multiple comparisons: choose the algorithm!
     */
    analysisPanel.getCorrectionComboBox().addActionListener((ActionEvent e) -> {
        int selectedIndex = analysisPanel.getAnalysisGroupList().getSelectedIndex();
        if (selectedIndex != -1) {
            SingleCellAnalysisGroup selectedGroup = groupsBindingList.get(selectedIndex);
            String correctionMethod = analysisPanel.getCorrectionComboBox().getSelectedItem().toString();

            // if the correction method is not "NONE"
            if (!correctionMethod.equals("none")) {
                // adjust p values
                singleCellStatisticsAnalyzer.correctForMultipleComparisons(selectedGroup, correctionMethod);
                // show p - values with the applied correction
                showPValues(selectedGroup, true);
            } else {
                // if selected correction method is "NONE", do not apply correction and only show normal p-values
                showPValues(selectedGroup, false);
            }
        }
    });

    /**
     * Perform statistical test: choose the test!!
     */
    analysisPanel.getPerformStatButton().addActionListener((ActionEvent e) -> {
        // get the selected test to be executed
        String selectedTest = analysisPanel.getStatTestComboBox().getSelectedItem().toString();
        String param = analysisPanel.getParameterComboBox().getSelectedItem().toString();
        // analysis group
        int selectedIndex = analysisPanel.getAnalysisGroupList().getSelectedIndex();
        if (selectedIndex != -1) {
            SingleCellAnalysisGroup selectedGroup = groupsBindingList.get(selectedIndex);
            computeStatistics(selectedGroup, selectedTest, param);
        }
    });

    //multiple comparison correction: set the default correction to none
    analysisPanel.getCorrectionComboBox().setSelectedIndex(0);
    analysisPanel.getStatTestComboBox().setSelectedIndex(0);
    analysisPanel.getParameterComboBox().setSelectedIndex(0);
}

From source file:es.emergya.ui.plugins.JButtonCellEditor.java

@Override
public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected,
        final int row, final int column) {
    JButton b = (JButton) value;
    b.setBorderPainted(false);/*from  w  w  w.  java 2s  . c  om*/
    b.setContentAreaFilled(false);
    b.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {
                @Override
                protected Object doInBackground() throws Exception {
                    stopCellEditing();
                    return null;
                }
            };
            SwingUtilities.invokeLater(sw);

            SwingWorker<Object, Object> sw1 = new SwingWorker<Object, Object>() {
                @Override
                protected Object doInBackground() throws Exception {
                    table.repaint();
                    return null;
                }
            };
            SwingUtilities.invokeLater(sw1);
        }
    });
    return b;
}

From source file:TableIt.java

public TableIt() {
    JFrame f = new JFrame();
    TableModel tm = new MyTableModel();
    final JTable table = new JTable(tm);

    TableColumnModel tcm = table.getColumnModel();
    TableColumn column = tcm.getColumn(tcm.getColumnCount() - 1);
    TableCellRenderer renderer = new MyTableCellRenderer();
    column.setCellRenderer(renderer);/*  w  w  w .  j  a  v a2s.co  m*/

    JButton selectionType = new JButton("Next Type");
    selectionType.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean rowSet = table.getRowSelectionAllowed();
            boolean colSet = table.getColumnSelectionAllowed();
            boolean cellSet = table.getCellSelectionEnabled();

            boolean setRow = !rowSet;
            boolean setCol = rowSet ^ colSet;
            boolean setCell = rowSet & colSet;

            table.setCellSelectionEnabled(setCell);
            table.setColumnSelectionAllowed(setCol);
            table.setRowSelectionAllowed(setRow);
            System.out.println("Row Selection Allowed? " + setRow);
            System.out.println("Column Selection Allowed? " + setCol);
            System.out.println("Cell Selection Enabled? " + setCell);
            table.repaint();
        }
    });
    JButton selectionMode = new JButton("Next Mode");
    selectionMode.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ListSelectionModel lsm = table.getSelectionModel();
            int mode = lsm.getSelectionMode();
            int nextMode;
            String nextModeString;
            if (mode == ListSelectionModel.SINGLE_SELECTION) {
                nextMode = ListSelectionModel.SINGLE_INTERVAL_SELECTION;
                nextModeString = "Single Interval Selection";
            } else if (mode == ListSelectionModel.SINGLE_INTERVAL_SELECTION) {
                nextMode = ListSelectionModel.MULTIPLE_INTERVAL_SELECTION;
                nextModeString = "Multiple Interval Selection";
            } else {
                nextMode = ListSelectionModel.SINGLE_SELECTION;
                nextModeString = "Single Selection";
            }
            lsm.setSelectionMode(nextMode);
            System.out.println("Selection Mode: " + nextModeString);
            table.repaint();
        }
    });
    JPanel jp = new JPanel();
    jp.add(selectionType);
    jp.add(selectionMode);
    JScrollPane jsp = new JScrollPane(table);
    Container c = f.getContentPane();
    c.add(jsp, BorderLayout.CENTER);
    c.add(jp, BorderLayout.SOUTH);
    f.setSize(300, 250);
    f.show();
}

From source file:com.aw.swing.mvp.binding.component.support.ColumnInfo.java

public void onActionPerformed(JTable table, AWTEvent actionEvent, Object obj, Object newValue) {
    List<ColumnActionListener> columnActionListeners = getColumnActionListenerList();
    boolean refreshRow = false;

    for (ColumnActionListener columnActionListener : columnActionListeners) {
        boolean refreshRowAux = columnActionListener.actionPerformed(actionEvent, obj, newValue);
        refreshRow = refreshRow || refreshRowAux;
    }/*from  w ww .jav  a  2 s . co m*/
    table.repaint();
}

From source file:com.aw.swing.mvp.binding.component.support.ColumnInfo.java

public void onClick(JTable table, MouseEvent actionEvent, Object obj, Object newValue) {
    List<ColumnActionListener> columnActionListeners = getColumnOnClickListenerList();
    boolean refreshRow = false;

    for (ColumnActionListener columnActionListener : columnActionListeners) {
        boolean refreshRowAux = columnActionListener.actionPerformed(actionEvent, obj, newValue);
        refreshRow = refreshRow || refreshRowAux;
    }/*from ww  w. j a  v a  2s .c o  m*/
    table.repaint();
}

From source file:app.RunApp.java

/**
 * Action for All button from principal tab
 * //from  w w w. j  a v  a  2  s .com
 * @param evt Event
 * @param jtable Table
 */
private void buttonAllActionPerformedPrincipal(java.awt.event.ActionEvent evt, JTable jtable) {
    TableModel tmodel = jtable.getModel();

    for (int i = 0; i < tmodel.getRowCount(); i++) {
        tmodel.setValueAt(Boolean.TRUE, i, 2);
    }

    jtable.setModel(tmodel);
    jtable.repaint();
}

From source file:app.RunApp.java

/**
 * Action for All button from multiple datasets tab
 * //from w ww . jav a  2 s  . c  o  m
 * @param evt Event
 * @param jtable Table
 */
private void buttonAllActionPerformedMulti(java.awt.event.ActionEvent evt, JTable jtable) {
    TableModel tmodel = jtable.getModel();

    for (int i = 0; i < tmodel.getRowCount(); i++) {
        tmodel.setValueAt(Boolean.TRUE, i, 1);
    }

    jtable.setModel(tmodel);
    jtable.repaint();
}

From source file:app.RunApp.java

/**
 * Action for None button from principal tab
 * /*  w ww  .  jav a 2 s.  c  om*/
 * @param evt Event
 * @param jtable Table
 */
private void buttonNoneActionPerformedPrincipal(java.awt.event.ActionEvent evt, JTable jtable) {
    TableModel tmodel = jtable.getModel();

    for (int i = 0; i < tmodel.getRowCount(); i++) {
        tmodel.setValueAt(Boolean.FALSE, i, 2);
    }

    jtable.setModel(tmodel);
    jtable.repaint();
}

From source file:app.RunApp.java

/**
 * Action for None button from multiple datasets tab
 * //  w  w  w .  j  a v  a 2 s.  c  o m
 * @param evt Event
 * @param jtable Table
 */
private void buttonNoneActionPerformedMulti(java.awt.event.ActionEvent evt, JTable jtable) {
    TableModel tmodel = jtable.getModel();

    for (int i = 0; i < tmodel.getRowCount(); i++) {
        tmodel.setValueAt(Boolean.FALSE, i, 1);
    }

    jtable.setModel(tmodel);
    jtable.repaint();
}

From source file:app.RunApp.java

/**
 * Action for Invert button from principal tab
 * //from w  w  w  .j a v  a 2 s  .  com
 * @param evt Event
 * @param jtable Table
 */
private void buttonInvertActionButtonPerformed(java.awt.event.ActionEvent evt, JTable jtable) {
    TableModel tmodel = jtable.getModel();

    for (int i = 0; i < tmodel.getRowCount(); i++) {
        if ((Boolean) tmodel.getValueAt(i, 2)) {
            tmodel.setValueAt(Boolean.FALSE, i, 2);
        } else {
            tmodel.setValueAt(Boolean.TRUE, i, 2);
        }
    }

    jtable.setModel(tmodel);
    jtable.repaint();
}