Java by API/javax.swing/JTableHeader

Материал из Java эксперт
Перейти к: навигация, поиск

JTableHeader: resizeAndRepaint()

  

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class Main {
  public static void main(String[] argv) throws Exception {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
    model.addColumn("Col1");
    model.addColumn("Col2");
    table.getColumnModel().getColumn(0).setHeaderValue("New Name");
    table.getTableHeader().resizeAndRepaint();
  }
}





JTableHeader: setReorderingAllowed(boolean reorderingAllowed)

  
import javax.swing.JTable;
public class Main {
  public static void main(String[] argv) throws Exception {
    int rows = 3;
    int cols = 3;
    JTable table = new JTable(rows, cols);
    table.getTableHeader().setReorderingAllowed(false);
    table.moveColumn(table.getColumnCount() - 1, 0);
  }
}





JTableHeader: setResizingAllowed(boolean resizingAllowed)

  
import javax.swing.JTable;
public class Main {
  public static void main(String[] argv) throws Exception {
    int rows = 3;
    int cols = 3;
    JTable table = new JTable(rows, cols);
    table.getTableHeader().setResizingAllowed(false);
  }
}