Popular Posts
Export list schema from sharepoint http:// YOUR_SERVER_URL / PATH_TO_SITE_CONTAINING_LIST /_vti_bin/owssvr.dll?Cmd=ExportList&List= {YOUR_LIST_GUID} JSRequest, Get parameters from querystring with javascript in SharePoint Provides method to parse query string, filename, and pathname from URL // Initialize first JSRequest.EnsureSetup(); // Get the current fil... ROBOCOPY: Robust File Copy for Windows -------------------------------------------------------------------------------    ROBOCOPY     ::     Robust File Copy for Windows --------...
Blog Archive
Stats
Default checkbox renderer in JTabel
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class CheckBoxCellinTable extends JFrame {

    JTable table;

    public CheckBoxCellinTable() {

        this.setLayout(new BorderLayout());
        this.initTable();

        setSize(400, 300);
        Dimension sc = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((sc.width - getWidth()) / 2, (sc.height - getHeight()) / 2);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    void initTable() {
        Object[] columnNames = { "First Name", "Last Name", "Married" };
        Object[][] data = { { "Harry", "Smith", true }, { "Sally", "Jones", false }, { "Bob", "Clark", true }, { "Eric", "Burke", true } };

        DefaultTableModel model = new DefaultTableModel(data, columnNames) {
            @Override
            public boolean isCellEditable(int row, int column) {
                return column == 2;
            }

            @Override
            public Class<?> getColumnClass(int columnIndex) {
                return columnIndex == 2 ? Boolean.class : super.getColumnClass(columnIndex);
            }
        };
        table = new JTable(model);

        this.add(new JScrollPane(table), BorderLayout.CENTER);
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new CheckBoxCellinTable();
    }

}
View mobile version