Example usage for javax.swing JTable getTableHeader

List of usage examples for javax.swing JTable getTableHeader

Introduction

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

Prototype

public JTableHeader getTableHeader() 

Source Link

Document

Returns the tableHeader used by this JTable.

Usage

From source file:org.o3project.optsdn.don.frame.NeFrame.java

/**
 * Create a pane that displays OMS connection information.
 * /*from   w  w  w. j a v  a2  s. c  om*/
 * @return The pane that displays OMS connection information
 */
private JScrollPane createOmsConnectionInfoPane() {
    Object[] header = OMS_CONNECTION_INFO_COLNAME_LIST.toArray();

    String[][] rowDataList = new String[omsConnectionInfoList.size()][header.length];
    for (int i = 0; i < rowDataList.length; i++) {
        List<Port> omsConnectionInfo = omsConnectionInfoList.get(i);

        Port port = omsConnectionInfo.get(0);
        int ofPortIndex = OMS_CONNECTION_INFO_COLNAME_LIST.indexOf(OmsConnectionInfoCols.OF_PORT.getName());
        Integer openFlowPortId1 = port.getOpenFlowPortId();
        String ofPortValue1;
        if (openFlowPortId1 == null) {
            ofPortValue1 = OFPORT_NOTFOUND;
        } else {
            ofPortValue1 = String.valueOf(openFlowPortId1);
        }
        rowDataList[i][ofPortIndex] = ofPortValue1;

        Port port2 = omsConnectionInfo.get(1);
        int connectedToIndex = OMS_CONNECTION_INFO_COLNAME_LIST
                .indexOf(OmsConnectionInfoCols.CONNECTED_TO.getName());
        Integer openFlowPortId2 = port2.getOpenFlowPortId();
        String ofPortValue2;
        if (openFlowPortId2 == null) {
            ofPortValue2 = OFPORT_NOTFOUND;
        } else {
            ofPortValue2 = String.valueOf(openFlowPortId2);
        }
        rowDataList[i][connectedToIndex] = port2.getNeId() + ", " + ofPortValue2;
    }

    JTable connectedTable = new JTable(rowDataList, header);

    connectedTable.getTableHeader().setBackground(Color.WHITE);

    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setHorizontalAlignment(SwingConstants.CENTER);
    for (int i = 0; i < header.length; i++) {
        TableColumn column = connectedTable.getColumnModel().getColumn(i);
        column.setCellRenderer(renderer);
    }

    JScrollPane connectedPane = new JScrollPane();
    connectedPane.getViewport().setView(connectedTable);
    connectedPane.setPreferredSize(new Dimension(connectedPane.getPreferredSize().width, TABLE_HEIGHT));
    return connectedPane;
}

From source file:org.o3project.optsdn.don.frame.NeFrame.java

/**
 * Create a pane that displays Information Model ID list.
 * /*from  www.jav a  2s  .c  o  m*/
 * @param portList Ports
 * @return The pane that displays Information Model ID list
 */
private JScrollPane createInformationModelIdListPane(List<Port> portList) {
    Collections.sort(portList, new PortComparator());

    Object[] columnNames = INFORMATION_MODEL_ID_COLNAME_LIST.toArray();
    DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0);
    for (Port port : portList) {
        Port[] column = { port, port };
        tableModel.addRow(column);
    }

    JTable informationModeldTable = new JTable(tableModel);
    informationModeldTable.getTableHeader().setBackground(Color.WHITE);

    DefaultTableCellRenderer renderer = new InformationModelIdRenderer();
    renderer.setHorizontalAlignment(SwingConstants.CENTER);
    informationModeldTable.setDefaultRenderer(Object.class, renderer);

    JScrollPane informationModelIdPane = new JScrollPane();
    informationModelIdPane.getViewport().setView(informationModeldTable);
    informationModelIdPane
            .setPreferredSize(new Dimension(informationModelIdPane.getPreferredSize().width, TABLE_HEIGHT));

    return informationModelIdPane;
}

From source file:org.openconcerto.erp.core.finance.accounting.element.AssociationCompteAnalytiqueSQLElement.java

public JTable creerJTable(ClasseCompte ccTmp) {
    final AssociationAnalytiqueModel model = new AssociationAnalytiqueModel(ccTmp);
    final JTable table = new JTable(model);
    final Vector vect = model.getRepartitionsAxe();
    table.getColumnModel().getColumn(0).setCellRenderer(new PlanComptableCellRenderer(0));
    table.getColumnModel().getColumn(1).setCellRenderer(new PlanComptableCellRenderer(0));

    for (int i = 0; i < vect.size(); i++) {
        final Vector rep = (Vector) vect.get(i);
        JComboBox combo = new JComboBox();
        for (int j = 0; j < rep.size(); j++) {
            combo.addItem(rep.get(j));/*w  w w . j  a  v  a 2  s . co  m*/
        }
        table.getColumnModel().getColumn(i + 2).setCellEditor(new DefaultCellEditor(combo));
        table.getColumnModel().getColumn(i + 2).setCellRenderer(new PlanComptableCellRenderer(0));
    }
    table.getTableHeader().setReorderingAllowed(false);
    return table;
}

From source file:org.openconcerto.erp.core.finance.accounting.ui.GrandLivrePanel.java

private JTable creerJTable(Compte compte) {

    ConsultCompteModel model = new ConsultCompteModel(compte);
    TableSorter s = new TableSorter(model);
    JTable tableTmp = new JTable(s);
    s.setTableHeader(tableTmp.getTableHeader());
    if (model.getEcritures() != null) {

        return tableTmp;
    } else {//from  ww  w  .j  av  a2 s . c  om
        return null;
    }
}

From source file:org.openconcerto.erp.core.finance.accounting.ui.PlanComptableGPanel.java

public JTable creerJTable(ClasseCompte ccTmp) { // NO_UCD

    final PlanComptableGModel model;
    if (this.radioCompteDeveloppe.isSelected()) {
        model = new PlanComptableGModel(ccTmp, 3);
    } else if (this.radioCompteAbrege.isSelected()) {
        model = new PlanComptableGModel(ccTmp, 2);
    } else {//from   w w w  .j  a v a2 s  . co  m
        model = new PlanComptableGModel(ccTmp, 1);
    }

    final JTable table = new JTable(model) {
        public JToolTip createToolTip() {
            JMultiLineToolTip t = new JMultiLineToolTip();
            t.setFixedWidth(500);
            return t;
        }
    };

    table.getColumnModel().getColumn(0).setCellRenderer(new PlanComptableCellRenderer(0));
    table.getColumnModel().getColumn(1).setCellRenderer(new PlanComptableCellRenderer(0));

    // TODO calcul de la taille de la colone numero de compte
    table.getColumnModel().getColumn(0).setMaxWidth(90);

    table.getTableHeader().setReorderingAllowed(false);

    table.addMouseMotionListener(new MouseMotionAdapter() {
        int lastRow = -1;

        public void mouseMoved(final MouseEvent e) {

            final Point p = new Point(e.getX(), e.getY());

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    final int row = table.rowAtPoint(p);
                    if (lastRow != row) {
                        lastRow = row;
                        String strTmp = ((Compte) (model.getComptes().get(lastRow))).getInfos();

                        if (strTmp.length() != 0) {
                            table.setToolTipText(strTmp);
                        } else {
                            table.setToolTipText(null);
                        }

                    }
                }
            });

        }
    });

    if (this.actionClickDroit != null) {
        // System.out.println("Ajout menu droit");
        table.addMouseListener(new MouseAdapter() {

            public void mousePressed(MouseEvent e) {

                if (e.getButton() == MouseEvent.BUTTON3) {
                    actionDroitTable(e, table);
                }
            }
        });
    }

    // Enable row selection (default)
    /**
     * table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true);
     * 
     * table.setSelectionMode(table.getSelectionModel().MULTIPLE_INTERVAL_SELECTION);
     */

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            int selectedRow = table.getSelectedRow();
            if (selectedRow < 0) {
                // Pas de selection
                textInfos.setText("Pas de compte slctionn");
            } else {
                textInfos.setText(((Compte) (model.getComptes().get(selectedRow))).getInfos());
            }
        }
    });

    return table;
}

From source file:org.processmining.analysis.performance.dottedchart.ui.MetricsPanel.java

/**
 * Displays the performance metrics of each pattern on the east side of the
 * plug-in window./*from   www  .j  a va 2s.c o  m*/
 * 
 * @param sortedArray
 *            int[]
 */

public void displayPerformanceMetrics() {
    String type = dcPanel.getTimeOption();
    ArrayList<DescriptiveStatistics> aList = dcModel.getTimeStatistics();
    ArrayList<String> aTitles = dcModel.getDescriptiveStatisticsTitles();

    ArrayList<String> sortedTitleList = dcModel.getSortedKeySetList();

    this.removeAll();
    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    // add time option menu
    this.add(Box.createRigidArea(new Dimension(5, 10)));
    JPanel menuPanel = new JPanel(new BorderLayout());
    menuPanel.setPreferredSize(new Dimension(160, 45));
    menuPanel.setMaximumSize(new Dimension(180, 45));
    timeSortLabel.setAlignmentX(LEFT_ALIGNMENT);
    menuPanel.add(timeSortLabel, BorderLayout.NORTH);
    timeBox.setMaximumSize(new Dimension(160, 20));
    timeBox.setAlignmentX(LEFT_ALIGNMENT);
    menuPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    menuPanel.add(timeBox, BorderLayout.CENTER);
    this.add(menuPanel);
    this.add(Box.createRigidArea(new Dimension(5, 10)));

    // for each frequency get the set of patterns that have that frequency
    // (run from high frequency to low)
    int size = 0;
    for (int i = 0; i < aList.size(); i++) {
        try {
            String key;
            DescriptiveStatistics currentDS = null;
            if (i != 0)
                key = sortedTitleList.get(i - 1);
            else {
                key = aTitles.get(0);
                currentDS = aList.get(i);
            }

            if (i > 0 && dcModel.getTypeHashMap().equals(DottedChartPanel.ST_INST)
                    && !dcModel.getInstanceTypeToKeep().contains(key))
                continue;
            size++;

            if (i > 0) {
                for (int j = 1; j < aTitles.size(); j++) {
                    if (aTitles.get(j).equals(key))
                        currentDS = aList.get(j);
                }
            }
            AbstractTableModel otm;
            // create labels that contains information about the pattern
            if (i == 0)
                otm = new OverallMetricTableModel();
            else
                otm = new OneMetricTableModel();
            DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer();
            dtcr.setBackground(new Color(235, 235, 235));
            JTable table = new JTable(otm);
            table.setPreferredSize(new Dimension(200, 55));
            table.setMaximumSize(new Dimension(200, 55));
            table.getColumnModel().getColumn(0).setPreferredWidth(70);
            table.getColumnModel().getColumn(0).setMaxWidth(100);
            table.getTableHeader().setFont(new Font("SansSerif", Font.PLAIN, 12));
            table.getColumnModel().getColumn(0).setCellRenderer(dtcr);
            table.setBorder(BorderFactory.createEtchedBorder());

            // place throughput times in table
            if (type.equals(DottedChartPanel.TIME_ACTUAL)) {
                if (i == 0) {
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getStartDateofLogUniList(key)), 0,
                            1);
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getEndDateofLogUniList(key)), 1,
                            1);
                }
                table.setValueAt(formatString(currentDS.getMean() / timeDivider, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / timeDivider, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / timeDivider, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_RELATIVE_TIME)) {
                if (i == 0) {
                    table.setValueAt(formatDate(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(formatDate(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(formatDate(dcModel.getStartDateofLogUniList(key)), 0, 1);
                    table.setValueAt(formatDate(dcModel.getEndDateofLogUniList(key)), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean() / timeDivider, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / timeDivider, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / timeDivider, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_RELATIVE_RATIO)) {
                if (i == 0) {
                    table.setValueAt(formatRatio(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(formatRatio(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(formatRatio(dcModel.getStartDateofLogUniList(key)), 0, 1);
                    table.setValueAt(formatRatio(dcModel.getEndDateofLogUniList(key)), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean() / 100, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / 100, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / 100, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_LOGICAL)
                    || type.equals(DottedChartPanel.TIME_LOGICAL_RELATIVE)) {
                if (i == 0) {
                    table.setValueAt(formatString(dcModel.getLogBoundaryLeft().getTime(), 5), 0, 1);
                    table.setValueAt(formatString(dcModel.getLogBoundaryRight().getTime(), 5), 1, 1);
                } else {
                    table.setValueAt(formatString((dcModel.getStartDateofLogUniList(key)).getTime(), 5), 0, 1);
                    table.setValueAt(formatString((dcModel.getEndDateofLogUniList(key)).getTime(), 5), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean(), 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin(), 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax(), 5), 4, 1);
            }

            JPanel tempPanel = new JPanel(new BorderLayout());
            table.setAlignmentX(CENTER_ALIGNMENT);
            tempPanel.setPreferredSize(new Dimension(160, 98));
            tempPanel.setMaximumSize(new Dimension(180, 98));
            tempPanel.add(table.getTableHeader(), BorderLayout.NORTH);
            tempPanel.add(table, BorderLayout.CENTER);
            JPanel tempPanel2 = new JPanel(new BorderLayout());
            JLabel patternLabel = new JLabel("Component " + key + ":");
            patternLabel.setAlignmentX(LEFT_ALIGNMENT);

            JLabel frequencyLabel = null;
            if (i == 0)
                frequencyLabel = new JLabel("# of components: " + currentDS.getN());
            else
                frequencyLabel = new JLabel("# of dots: " + dcModel.getNumberOfLogUnits(key));

            frequencyLabel.setAlignmentX(LEFT_ALIGNMENT);
            frequencyLabel.setFont(new Font("SansSerif", Font.PLAIN, 12));
            tempPanel2.add(patternLabel, BorderLayout.NORTH);
            tempPanel2.add(frequencyLabel, BorderLayout.CENTER);
            tempPanel2.add(tempPanel, BorderLayout.SOUTH);
            this.add(tempPanel2);
            this.add(Box.createRigidArea(new Dimension(5, 10)));
        } catch (NullPointerException ex) {
            // can occur when patternMap does not contain a pattern with
            // this frequency
            size--;
        }
    }
    // make sure the pattern performance information is displayed properly
    this.setPreferredSize(new Dimension(200, 140 * (size + 1)));
    this.revalidate();
    this.repaint();

}

From source file:org.prom5.analysis.performance.dottedchart.ui.MetricsPanel.java

/**
 * Displays the performance metrics of each pattern on the east side of the
 * plug-in window./*from   w w  w.  jav a  2  s  .c om*/
 * @param sortedArray int[]
 */

public void displayPerformanceMetrics() {
    String type = dcPanel.getTimeOption();
    ArrayList<DescriptiveStatistics> aList = dcModel.getTimeStatistics();
    ArrayList<String> aTitles = dcModel.getDescriptiveStatisticsTitles();

    ArrayList<String> sortedTitleList = dcModel.getSortedKeySetList();

    this.removeAll();
    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    //add time option menu
    this.add(Box.createRigidArea(new Dimension(5, 10)));
    JPanel menuPanel = new JPanel(new BorderLayout());
    menuPanel.setPreferredSize(new Dimension(160, 45));
    menuPanel.setMaximumSize(new Dimension(180, 45));
    timeSortLabel.setAlignmentX(LEFT_ALIGNMENT);
    menuPanel.add(timeSortLabel, BorderLayout.NORTH);
    timeBox.setMaximumSize(new Dimension(160, 20));
    timeBox.setAlignmentX(LEFT_ALIGNMENT);
    menuPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    menuPanel.add(timeBox, BorderLayout.CENTER);
    this.add(menuPanel);
    this.add(Box.createRigidArea(new Dimension(5, 10)));

    //for each frequency get the set of patterns that have that frequency
    //(run from high frequency to low)
    int size = 0;
    for (int i = 0; i < aList.size(); i++) {
        try {
            String key;
            DescriptiveStatistics currentDS = null;
            if (i != 0)
                key = sortedTitleList.get(i - 1);
            else {
                key = aTitles.get(0);
                currentDS = aList.get(i);
            }

            if (i > 0 && dcModel.getTypeHashMap().equals(DottedChartPanel.ST_INST)
                    && !dcModel.getInstanceTypeToKeep().contains(key))
                continue;
            size++;

            if (i > 0) {
                for (int j = 1; j < aTitles.size(); j++) {
                    if (aTitles.get(j).equals(key))
                        currentDS = aList.get(j);
                }
            }
            AbstractTableModel otm;
            //create labels that contains information about the pattern
            if (i == 0)
                otm = new OverallMetricTableModel();
            else
                otm = new OneMetricTableModel();
            DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer();
            dtcr.setBackground(new Color(235, 235, 235));
            JTable table = new JTable(otm);
            table.setPreferredSize(new Dimension(200, 55));
            table.setMaximumSize(new Dimension(200, 55));
            table.getColumnModel().getColumn(0).setPreferredWidth(70);
            table.getColumnModel().getColumn(0).setMaxWidth(100);
            table.getTableHeader().setFont(new Font("SansSerif", Font.PLAIN, 12));
            table.getColumnModel().getColumn(0).setCellRenderer(dtcr);
            table.setBorder(BorderFactory.createEtchedBorder());

            //place throughput times in table
            if (type.equals(DottedChartPanel.TIME_ACTUAL)) {
                if (i == 0) {
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getStartDateofLogUniList(key)), 0,
                            1);
                    table.setValueAt(DateFormat.getInstance().format(dcModel.getEndDateofLogUniList(key)), 1,
                            1);
                }
                table.setValueAt(formatString(currentDS.getMean() / timeDivider, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / timeDivider, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / timeDivider, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_RELATIVE_TIME)) {
                if (i == 0) {
                    table.setValueAt(formatDate(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(formatDate(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(formatDate(dcModel.getStartDateofLogUniList(key)), 0, 1);
                    table.setValueAt(formatDate(dcModel.getEndDateofLogUniList(key)), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean() / timeDivider, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / timeDivider, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / timeDivider, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_RELATIVE_RATIO)) {
                if (i == 0) {
                    table.setValueAt(formatRatio(dcModel.getLogBoundaryLeft()), 0, 1);
                    table.setValueAt(formatRatio(dcModel.getLogBoundaryRight()), 1, 1);
                } else {
                    table.setValueAt(formatRatio(dcModel.getStartDateofLogUniList(key)), 0, 1);
                    table.setValueAt(formatRatio(dcModel.getEndDateofLogUniList(key)), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean() / 100, 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin() / 100, 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax() / 100, 5), 4, 1);
            } else if (type.equals(DottedChartPanel.TIME_LOGICAL)
                    || type.equals(DottedChartPanel.TIME_LOGICAL_RELATIVE)) {
                if (i == 0) {
                    table.setValueAt(formatString(dcModel.getLogBoundaryLeft().getTime(), 5), 0, 1);
                    table.setValueAt(formatString(dcModel.getLogBoundaryRight().getTime(), 5), 1, 1);
                } else {
                    table.setValueAt(formatString((dcModel.getStartDateofLogUniList(key)).getTime(), 5), 0, 1);
                    table.setValueAt(formatString((dcModel.getEndDateofLogUniList(key)).getTime(), 5), 1, 1);
                }
                table.setValueAt(formatString(currentDS.getMean(), 5), 2, 1);
                table.setValueAt(formatString(currentDS.getMin(), 5), 3, 1);
                table.setValueAt(formatString(currentDS.getMax(), 5), 4, 1);
            }

            JPanel tempPanel = new JPanel(new BorderLayout());
            table.setAlignmentX(CENTER_ALIGNMENT);
            tempPanel.setPreferredSize(new Dimension(160, 98));
            tempPanel.setMaximumSize(new Dimension(180, 98));
            tempPanel.add(table.getTableHeader(), BorderLayout.NORTH);
            tempPanel.add(table, BorderLayout.CENTER);
            JPanel tempPanel2 = new JPanel(new BorderLayout());
            JLabel patternLabel = new JLabel("Component " + key + ":");
            patternLabel.setAlignmentX(LEFT_ALIGNMENT);

            JLabel frequencyLabel = null;
            if (i == 0)
                frequencyLabel = new JLabel("# of components: " + currentDS.getN());
            else
                frequencyLabel = new JLabel("# of dots: " + dcModel.getNumberOfLogUnits(key));

            frequencyLabel.setAlignmentX(LEFT_ALIGNMENT);
            frequencyLabel.setFont(new Font("SansSerif", Font.PLAIN, 12));
            tempPanel2.add(patternLabel, BorderLayout.NORTH);
            tempPanel2.add(frequencyLabel, BorderLayout.CENTER);
            tempPanel2.add(tempPanel, BorderLayout.SOUTH);
            this.add(tempPanel2);
            this.add(Box.createRigidArea(new Dimension(5, 10)));
        } catch (NullPointerException ex) {
            //can occur when patternMap does not contain a pattern with this frequency
            size--;
        }
    }
    //make sure the pattern performance information is displayed properly
    this.setPreferredSize(new Dimension(200, 140 * (size + 1)));
    this.revalidate();
    this.repaint();

}

From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewer.java

private void setupTable() {
    tableModel = new ElementListTableModel();
    table = new JXTable(tableModel);

    tableSorter = new ElementListTableSorter(tableModel, table);
    table.getTableHeader().addMouseListener(tableSorter); // add sorter & header renderer
    table.setColumnSelectionAllowed(false);
    table.setRowSelectionAllowed(true);/*from  w  w w  . j  a v a  2  s  .  c o m*/

    // set our column widths
    ElementListTableModel.setupColumnWidths(table);

    table.setDefaultRenderer(Object.class, new ElementListCellRenderer(this, false));
    table.setDefaultRenderer(Boolean.class, new BooleanCellRenderer(this, false));

    // hide irrelevent columns
    TableColumnModelExt colmodel = (TableColumnModelExt) table.getColumnModel();
    table.setColumnControlVisible(true);
    colmodel.getColumnExt(I18n.getText("hidden.MostRecentVersion")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.n")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.rec")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.hash")).setVisible(false);

    // popup menu
    table.addMouseListener(new PopupListener() {
        @Override
        public void showPopup(MouseEvent e) {
            // only clicks on tables
            if (!(e.getSource() instanceof JTable))
                return;

            JTable table = (JTable) e.getSource();
            ElementListTableModel model = (ElementListTableModel) table.getModel();

            // get the row and sanity check
            int row = table.rowAtPoint(e.getPoint());
            if (row < 0 || row >= model.getRowCount())
                return;

            // select it?
            table.setRowSelectionInterval(row, row);

            // get the element
            Element element = model.getElementAt(row);

            // create and show the menu
            JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewer.this);
            popup.show(table, e.getX(), e.getY());
        }
    });
}

From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewerOld.java

private void setupTable() {
    tableModel = new ElementListTableModel();
    table = new JXTable(tableModel);

    tableSorter = new ElementListTableSorter(tableModel, table);
    table.getTableHeader().addMouseListener(tableSorter); // add sorter & header renderer
    table.setColumnSelectionAllowed(false);
    table.setRowSelectionAllowed(true);//from   w  w w  .ja v  a  2  s  . c  o m

    // set our column widths
    ElementListTableModel.setupColumnWidths(table);

    table.setDefaultRenderer(Object.class, new ElementListCellRenderer(this, false));
    table.setDefaultRenderer(Boolean.class, new BooleanCellRenderer(this, false));

    // hide irrelevent columns
    TableColumnModelExt colmodel = (TableColumnModelExt) table.getColumnModel();
    table.setColumnControlVisible(true);
    colmodel.getColumnExt(I18n.getText("hidden.MostRecentVersion")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.n")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.rec")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.hash")).setVisible(false);

    // popup menu
    table.addMouseListener(new PopupListener() {
        @Override
        public void showPopup(MouseEvent e) {
            // only clicks on tables
            if (!(e.getSource() instanceof JTable))
                return;

            JTable table = (JTable) e.getSource();
            ElementListTableModel model = (ElementListTableModel) table.getModel();

            // get the row and sanity check
            int row = table.rowAtPoint(e.getPoint());
            if (row < 0 || row >= model.getRowCount())
                return;

            // select it?
            table.setRowSelectionInterval(row, row);

            // get the element
            Element element = model.getElementAt(row);

            // create and show the menu
            JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewerOld.this);
            popup.show(table, e.getX(), e.getY());
        }
    });
}

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// www .  jav  a 2  s .com

    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);
    }
}