[JAVA] How do I set or change JTable column width?

2015. 2. 25. 20:43Programing/Android / Java


아래 Code가 JTable에서 칼럼 폭을 설정해 주는 것입니다.

[How do I set or change JTable column width?]

    // Defines table's column width.

    int[] columnsWidth = {

            50, 150, 100, 150, 150

    };

        

    // Configures table's column width.

    int i = 0;

    for (int width : columnsWidth) {

        TableColumn column = mTable.getColumnModel().getColumn(i++);

        column.setMinWidth(width);

        column.setMaxWidth(width);

        column.setPreferredWidth(width);

    }


단, 주의점은 setMaxWidth를 설정해주게 되면, 그 이상으로 사이즈 조절이 불가능합니다.