List of usage examples for javax.swing.table TableColumnModel getColumn
public TableColumn getColumn(int columnIndex);
TableColumn
object for the column at columnIndex
. From source file:MainClass.java
public static void main(String args[]) { String rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } }; String headers[] = { "Upper", "Lower" }; JFrame frame = new JFrame("Tooltip Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(rows, headers); JLabel headerRenderer = new DefaultTableCellRenderer(); String columnName = table.getModel().getColumnName(0); headerRenderer.setText(columnName);/*ww w . j av a 2 s .c o m*/ headerRenderer.setToolTipText("Wave"); TableColumnModel columnModel = table.getColumnModel(); TableColumn column = columnModel.getColumn(0); column.setHeaderRenderer((TableCellRenderer) headerRenderer); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:LabelHeaderSample.java
public static void main(String args[]) { final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } }; JFrame frame = new JFrame("Label Header"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String headers[] = { "English", "#" }; JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); JLabel headerRenderer = new DefaultTableCellRenderer(); String columnName = table.getModel().getColumnName(0); headerRenderer.setText(columnName);//from w ww. j a v a2 s .c o m headerRenderer.setToolTipText("text"); TableColumnModel columnModel = table.getColumnModel(); TableColumn englishColumn = columnModel.getColumn(0); englishColumn.setHeaderRenderer((TableCellRenderer) headerRenderer); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:SwingToolTipSample.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("Tooltip Sample"); JTable table = new JTable(rows, headers); JLabel headerRenderer = new DefaultTableCellRenderer(); String columnName = table.getModel().getColumnName(0); headerRenderer.setText(columnName);/*from ww w .ja v a2s. c o m*/ headerRenderer.setToolTipText("Wave"); TableColumnModel columnModel = table.getColumnModel(); TableColumn englishColumn = columnModel.getColumn(0); englishColumn.setHeaderRenderer((TableCellRenderer) headerRenderer); JScrollPane scrollPane = new JScrollPane(table); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { String rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } }; String headers[] = { "Upper", "Lower" }; JFrame frame = new JFrame("Label Header"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); Border headerBorder = UIManager.getBorder("TableHeader.cellBorder"); JLabel headerLabel1 = new JLabel(headers[0], JLabel.CENTER); headerLabel1.setBorder(headerBorder); JLabel headerLabel2 = new JLabel(headers[1], JLabel.CENTER); headerLabel2.setBorder(headerBorder); TableCellRenderer renderer = new JComponentTableCellRenderer(); TableColumnModel columnModel = table.getColumnModel(); TableColumn column0 = columnModel.getColumn(0); TableColumn column1 = columnModel.getColumn(1); column0.setHeaderRenderer(renderer); column0.setHeaderValue(headerLabel1); column1.setHeaderRenderer(renderer); column1.setHeaderValue(headerLabel2); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150);/* www. j a va2 s . c om*/ frame.setVisible(true); }
From source file:JComponentTableCellRenderer.java
public static void main(String args[]) { final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } }; JFrame frame = new JFrame("Label Header"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String headers[] = { "English", "#" }; JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); Icon redIcon = new ImageIcon("yourFile.gif"); Icon blueIcon = new ImageIcon("yourFile.gif"); Border headerBorder = UIManager.getBorder("TableHeader.cellBorder"); JLabel blueLabel = new JLabel(headers[0], blueIcon, JLabel.CENTER); blueLabel.setBorder(headerBorder);//w w w . ja va2 s .c o m JLabel redLabel = new JLabel(headers[1], redIcon, JLabel.CENTER); redLabel.setBorder(headerBorder); TableCellRenderer renderer = new JComponentTableCellRenderer(); TableColumnModel columnModel = table.getColumnModel(); TableColumn column0 = columnModel.getColumn(0); TableColumn column1 = columnModel.getColumn(1); column0.setHeaderRenderer(renderer); column0.setHeaderValue(blueLabel); column1.setHeaderRenderer(renderer); column1.setHeaderValue(redLabel); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:LabelHeaderSample.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" } }; JFrame frame = new JFrame("Label Header"); String headers[] = { "English", "Japanese" }; JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); Icon redIcon = new DiamondIcon(Color.red); Icon blueIcon = new DiamondIcon(Color.blue); Border headerBorder = UIManager.getBorder("TableHeader.cellBorder"); JLabel blueLabel = new JLabel(headers[0], blueIcon, JLabel.CENTER); blueLabel.setBorder(headerBorder);/*w w w . j ava2 s.c o m*/ JLabel redLabel = new JLabel(headers[1], redIcon, JLabel.CENTER); redLabel.setBorder(headerBorder); TableCellRenderer renderer = new JComponentTableCellRenderer(); TableColumnModel columnModel = table.getColumnModel(); TableColumn column0 = columnModel.getColumn(0); TableColumn column1 = columnModel.getColumn(1); column0.setHeaderRenderer(renderer); column0.setHeaderValue(blueLabel); column1.setHeaderRenderer(renderer); column1.setHeaderValue(redLabel); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void setMinimumColumnWidths(final JTable table, final int... widths) { TableColumnModel columnModel = table.getColumnModel(); for (int col = 0; col < widths.length; col++) { columnModel.getColumn(col).setMinWidth(widths[col]); }/*ww w.j a v a 2 s. c om*/ }
From source file:Main.java
public static void setMaxnimumColumnWidths(final JTable table, final int... widths) { TableColumnModel columnModel = table.getColumnModel(); for (int col = 0; col < widths.length; col++) { columnModel.getColumn(col).setMaxWidth(widths[col]); }//www.j a va 2 s . c om }
From source file:Main.java
public static void setPreferredColumnWidths(final JTable table, final int... widths) { TableColumnModel columnModel = table.getColumnModel(); for (int col = 0; col < widths.length; col++) { columnModel.getColumn(col).setPreferredWidth(widths[col]); }/*from www . ja v a 2 s . c o m*/ }
From source file:Main.java
public static int getIndexAtColumnModel(TableColumnModel model, String name) { for (int i = 0; i < model.getColumnCount(); i++) { String headStr = model.getColumn(i).getHeaderValue().toString(); if (name.equals(headStr)) { return i; }/*from w ww . j av a 2 s .c om*/ } return 0; }