Example usage for javax.swing JTable setAlignmentX

List of usage examples for javax.swing JTable setAlignmentX

Introduction

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

Prototype

@BeanProperty(description = "The preferred horizontal alignment of the component.")
public void setAlignmentX(float alignmentX) 

Source Link

Document

Sets the horizontal alignment.

Usage

From source file:fs.MainWindow.java

public void GenerateTable(Object[][] data, String title, String subtitle, final String[] titles) {
    JFrame window = new JFrame(title);
    window.setLayout(new java.awt.BorderLayout(5, 5));
    JLabel label = new JLabel(subtitle);
    label.setFont(new java.awt.Font("Tahoma", 1, 12));
    label.setForeground(new java.awt.Color(0, 0, 255));
    label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    label.setOpaque(true);/*from www  .  j a  v  a  2s .c om*/
    label.setPreferredSize(new java.awt.Dimension(50, 30));

    ListModel lm = new AbstractListModel() {

        String headers[] = titles;

        @Override
        public int getSize() {
            return headers.length;
        }

        @Override
        public Object getElementAt(int index) {
            return headers[index];
        }
    };

    //        String[] titles = getClasses();
    JList rowHeader = new JList(lm);
    rowHeader.setFixedCellWidth(50);
    JTable jTable = new JTable(data, titles);
    rowHeader.setFixedCellHeight(jTable.getRowHeight());
    rowHeader.setCellRenderer(new RowHeaderRenderer(jTable));
    JScrollPane scroll = new JScrollPane(jTable);
    scroll.setRowHeaderView(rowHeader);
    getContentPane().add(scroll, BorderLayout.CENTER);

    jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    jTable.setAlignmentX(JTable.CENTER_ALIGNMENT);

    window.add(label, java.awt.BorderLayout.NORTH);
    window.add(scroll, java.awt.BorderLayout.CENTER);

    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    window.setBounds((screenSize.width - 800) / 2, (screenSize.height - 270) / 2, 800, 270);
    window.setVisible(true);
}

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./*w w w .  j a v  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.prom5.analysis.performance.dottedchart.ui.MetricsPanel.java

/**
 * Displays the performance metrics of each pattern on the east side of the
 * plug-in window./*from ww  w .ja  v a2  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();

}