Example usage for javax.swing.table TableColumnModel setColumnMargin

List of usage examples for javax.swing.table TableColumnModel setColumnMargin

Introduction

In this page you can find the example usage for javax.swing.table TableColumnModel setColumnMargin.

Prototype

public void setColumnMargin(int newMargin);

Source Link

Document

Sets the TableColumn's column margin to newMargin.

Usage

From source file:ColumnModelSample.java

public static void main(String args[]) {
    final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } };
    final Object headers[] = { "English", "#" };
    JFrame frame = new JFrame("Scrollless Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable table = new JTable(rows, headers);

    TableColumnModelListener tableColumnModelListener = new TableColumnModelListener() {
        public void columnAdded(TableColumnModelEvent e) {
            System.out.println("Added");
        }//from ww w .j a v  a2s  .com

        public void columnMarginChanged(ChangeEvent e) {
            System.out.println("Margin");
        }

        public void columnMoved(TableColumnModelEvent e) {
            System.out.println("Moved");
        }

        public void columnRemoved(TableColumnModelEvent e) {
            System.out.println("Removed");
        }

        public void columnSelectionChanged(ListSelectionEvent e) {
            System.out.println("Selection Changed");
        }
    };
    TableColumnModel columnModel = table.getColumnModel();
    columnModel.addColumnModelListener(tableColumnModelListener);

    columnModel.setColumnMargin(12);

    TableColumn column = new TableColumn(1);
    columnModel.addColumn(column);

    JScrollPane pane = new JScrollPane(table);
    frame.add(pane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    Object rows[][] = { { "one", "ichi - \u4E00" }, { "two", "ni - \u4E8C" }, { "three", "san - \u4E09" },
            { "four", "shi - \u56DB" }, { "five", "go - \u4E94" }, { "six", "roku - \u516D" },
            { "seven", "shichi - \u4E03" }, { "eight", "hachi - \u516B" }, { "nine", "kyu - \u4E5D" },
            { "ten", "ju - \u5341" } };
    Object headers[] = { "English", "Japanese" };
    JFrame frame = new JFrame("Scrollless Table");
    JTable table = new JTable(rows, headers);

    TableColumnModelListener tableColumnModelListener = new TableColumnModelListener() {
        public void columnAdded(TableColumnModelEvent e) {
            System.out.println("Added");
        }/*from   w  w  w .jav  a2  s  .com*/

        public void columnMarginChanged(ChangeEvent e) {
            System.out.println("Margin");
        }

        public void columnMoved(TableColumnModelEvent e) {
            System.out.println("Moved");
        }

        public void columnRemoved(TableColumnModelEvent e) {
            System.out.println("Removed");
        }

        public void columnSelectionChanged(ListSelectionEvent e) {
            System.out.println("Selection Changed");
        }
    };

    TableColumnModel columnModel = table.getColumnModel();
    columnModel.addColumnModelListener(tableColumnModelListener);

    columnModel.setColumnMargin(12);

    TableColumn column = new TableColumn(1);
    columnModel.addColumn(column);

    frame.getContentPane().add(table, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    Object rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } };
    Object headers[] = { "Upper", "Lower" };

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable table = new JTable(rows, headers);

    TableColumnModelListener tableColumnModelListener = new TableColumnModelListener() {
        public void columnAdded(TableColumnModelEvent e) {
            System.out.println("Added");
        }//from  ww  w . j av  a 2s  .c  o  m

        public void columnMarginChanged(ChangeEvent e) {
            System.out.println("Margin");
        }

        public void columnMoved(TableColumnModelEvent e) {
            System.out.println("Moved");
        }

        public void columnRemoved(TableColumnModelEvent e) {
            System.out.println("Removed");
        }

        public void columnSelectionChanged(ListSelectionEvent e) {
            System.out.println("Selection Changed");
        }
    };

    TableColumnModel columnModel = table.getColumnModel();
    columnModel.addColumnModelListener(tableColumnModelListener);

    columnModel.setColumnMargin(12);

    TableColumn column = new TableColumn(1);
    columnModel.addColumn(column);

    JScrollPane pane = new JScrollPane(table);
    frame.add(pane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}