List of usage examples for javax.swing JTable getTableHeader
public JTableHeader getTableHeader()
tableHeader
used by this JTable
. From source file:Main.java
public static void main(String[] argv) throws Exception { int rows = 3; int cols = 3; JTable table = new JTable(rows, cols); table.getTableHeader().setResizingAllowed(false); }
From source file:Main.java
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); }
From source file:Main.java
public static void main(String[] args) { Integer[][] data = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; String[] cols = { "A", "B", "C" }; JTable table = new JTable(data, cols); JTableHeader header = table.getTableHeader(); header.setBackground(Color.black); header.setForeground(Color.yellow); JOptionPane.showMessageDialog(null, new JScrollPane(table)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { int rows = 10; int cols = 5; JTable table = new JTable(rows, cols); JTableHeader header = table.getTableHeader(); JPanel container = new JPanel(new BorderLayout()); // Add header in NORTH slot container.add(header, BorderLayout.NORTH); // Add table itself to CENTER slot container.add(table, BorderLayout.CENTER); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(5, 5); JTableHeader header = table.getTableHeader(); header.addMouseListener(new ColumnHeaderListener()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { int rows = 10; int cols = 5; JTable table = new JTable(rows, cols); JTableHeader header = table.getTableHeader(); ColumnHeaderToolTips tips = new ColumnHeaderToolTips(); for (int c = 0; c < table.getColumnCount(); c++) { TableColumn col = table.getColumnModel().getColumn(c); tips.setToolTip(col, "Col " + c); }//from w ww . j ava 2s . c o m header.addMouseMotionListener(tips); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addColumn("Col2"); table.getTableHeader().getColumnModel().getColumn(1).setHeaderRenderer(new IconHeaderRenderer()); table.getColumnModel().getColumn(1).setHeaderValue(new TextAndIcon("Col2", new ImageIcon("icon.gif"))); }
From source file:Main.java
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(); }
From source file:Main.java
public static void main(String[] args) { Main testJFrame = new Main(); List<String> columns = new ArrayList<String>(); List<String[]> values = new ArrayList<String[]>(); columns.add("col1"); columns.add("col2"); columns.add("col3"); for (int i = 0; i < 100; i++) { values.add(new String[] { "val" + i + " col1", "val" + i + " col2", "val" + i + " col3" }); }//from www .j a v a 2 s. c om TableModel tableModel = new DefaultTableModel(values.toArray(new Object[][] {}), columns.toArray()); JTable table = new JTable(tableModel); testJFrame.setLayout(new BorderLayout()); testJFrame.add(new JScrollPane(table), BorderLayout.CENTER); testJFrame.add(table.getTableHeader(), BorderLayout.NORTH); testJFrame.setVisible(true); testJFrame.setSize(200, 200); }
From source file:Main.java
public static void main(String[] args) throws Exception { Object[][] data = { { "A", new Integer(3), new Double(7.23), new Boolean(true) }, { "J", new Integer(2), new Double(4.64), new Boolean(false) }, { "S", new Integer(1), new Double(8.81), new Boolean(true) } }; String[] columns = { "Col", "Col", "Col", "Col" }; JTable table = new JTable(data, columns); JScrollPane scroll = new JScrollPane(table); JFrame f = new JFrame(); f.setContentPane(scroll);// w w w.jav a 2 s . c o m f.pack(); int x = (int) table.getTableHeader().getSize().getWidth(); int y = (int) table.getTableHeader().getSize().getHeight() + (int) table.getSize().getHeight(); BufferedImage bi = new BufferedImage((int) x, (int) y, BufferedImage.TYPE_INT_RGB); Graphics g = bi.createGraphics(); table.getTableHeader().paint(g); g.translate(0, table.getTableHeader().getHeight()); table.paint(g); g.dispose(); JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(bi))); ImageIO.write(bi, "png", new File("c:/Java_Dev/table.png")); System.exit(0); }