Package eas.startSetup.tableExamples

Source Code of eas.startSetup.tableExamples.TestTable

package eas.startSetup.tableExamples;

import javax.swing.DefaultCellEditor;
import javax.swing.Icon;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

public class TestTable {

    public static void main(String[] args) {
        Object[][] data = { { "True icon", Boolean.TRUE },
                { "False icon", Boolean.FALSE } };
        String[] columnNames = { "Type", "Icon" };
        TableModel model = new DefaultTableModel(data, columnNames) {
            private static final long serialVersionUID = 1L;

            @SuppressWarnings({ "unchecked", "rawtypes" })
            @Override
            public Class getColumnClass(int columnIndex) {
                return columnIndex == 1 ? Boolean.class : Object.class;
            }
        };
        JTable table = new JTable(model);
        Icon icon = new TestTableIcon();
        JCheckBox check = (JCheckBox) table.getDefaultRenderer(Boolean.class);
        check.setIcon(icon);
        DefaultCellEditor editor = (DefaultCellEditor) table.getDefaultEditor(Boolean.class);
        ((JCheckBox) editor.getComponent()).setIcon(icon);

        final JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new JScrollPane(table));
        f.pack();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                f.setLocationRelativeTo(null);
                f.setVisible(true);
            }
        });
    }
}
TOP

Related Classes of eas.startSetup.tableExamples.TestTable

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.