List of usage examples for javax.swing JTable getTableHeader
public JTableHeader getTableHeader()
tableHeader
used by this JTable
. From source file:com.intel.stl.ui.common.view.ComponentFactory.java
public static JTable createIntelNonSortableSimpleTable(Object[][] rowData, Object[] columnNames) { JTable table = new JTable(rowData, columnNames); table.setBackground(UIConstants.INTEL_WHITE); table.getTableHeader().setBackground(UIConstants.INTEL_BORDER_GRAY); table.getTableHeader().setForeground(UIConstants.INTEL_DARK_GRAY); table.getTableHeader().setFont(UIConstants.H5_FONT.deriveFont(Font.BOLD)); return table; }
From source file:ExtendedDnDDemo.java
private JPanel createTable() { DefaultTableModel model = new DefaultTableModel(); model.addColumn("Column 0"); model.addColumn("Column 1"); model.addColumn("Column 2"); model.addColumn("Column 3"); model.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" }); model.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" }); model.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" }); model.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" }); JTable table = new JTable(model); table.getTableHeader().setReorderingAllowed(false); table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); JScrollPane scrollPane = new JScrollPane(table); scrollPane.setPreferredSize(new Dimension(400, 100)); table.setDragEnabled(true);// w w w .j a v a2 s .c om table.setTransferHandler(new TableTransferHandler()); JPanel panel = new JPanel(new BorderLayout()); panel.add(scrollPane, BorderLayout.CENTER); panel.setBorder(BorderFactory.createTitledBorder("Table")); return panel; }
From source file:Main.java
public Main() { JTable table = new JTable(3, 3); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); for (int i = 0; i < table.getColumnCount(); i++) { DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel(); TableColumn col = colModel.getColumn(i); int width = 0; TableCellRenderer renderer = col.getHeaderRenderer(); if (renderer == null) { renderer = table.getTableHeader().getDefaultRenderer(); }//from www . j a va 2 s . co m Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0); width = comp.getPreferredSize().width; col.setPreferredWidth(width + 2); } JFrame f = new JFrame(); f.add(new JScrollPane(table)); f.setSize(300, 300); f.setVisible(true); }
From source file:TableRenderDemo.java
private void initColumnSizes(JTable table) { MyTableModel model = (MyTableModel) table.getModel(); TableColumn column = null;//from w w w . j a v a 2s . com Component comp = null; int headerWidth = 0; int cellWidth = 0; Object[] longValues = model.longValues; TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); for (int i = 0; i < 5; i++) { column = table.getColumnModel().getColumn(i); comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; comp = table.getDefaultRenderer(model.getColumnClass(i)).getTableCellRendererComponent(table, longValues[i], false, false, 0, i); cellWidth = comp.getPreferredSize().width; if (DEBUG) { System.out.println("Initializing width of column " + i + ". " + "headerWidth = " + headerWidth + "; cellWidth = " + cellWidth); } // XXX: Before Swing 1.1 Beta 2, use setMinWidth instead. column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
From source file:components.TableRenderDemo.java
private void initColumnSizes(JTable table) { MyTableModel model = (MyTableModel) table.getModel(); TableColumn column = null;/*from www . ja v a 2 s. c o m*/ Component comp = null; int headerWidth = 0; int cellWidth = 0; Object[] longValues = model.longValues; TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); for (int i = 0; i < 5; i++) { column = table.getColumnModel().getColumn(i); comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; comp = table.getDefaultRenderer(model.getColumnClass(i)).getTableCellRendererComponent(table, longValues[i], false, false, 0, i); cellWidth = comp.getPreferredSize().width; if (DEBUG) { System.out.println("Initializing width of column " + i + ". " + "headerWidth = " + headerWidth + "; cellWidth = " + cellWidth); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
From source file:logdruid.ui.mainpanel.EventRecordingSelectorPanel.java
private void initColumnSizes(JTable theTable) { TableColumn column = null;/*w ww .j a v a2 s. co m*/ Component comp = null; int headerWidth = 0; int cellWidth = 0; TableCellRenderer headerRenderer = theTable.getTableHeader().getDefaultRenderer(); for (int i = 0; i < 4; i++) { column = theTable.getColumnModel().getColumn(i); comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; cellWidth = comp.getPreferredSize().width; column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
From source file:Main.java
public static void SetJTableAlignment(javax.swing.JTable jTable, ComponentOrientation componentOrientation) { Font tahoma = new Font("Tahoma", Font.PLAIN, 11); int labelAlighnment = JLabel.RIGHT; int headerAlighnment = JLabel.RIGHT; if (componentOrientation == ComponentOrientation.LEFT_TO_RIGHT) { labelAlighnment = JLabel.LEFT; headerAlighnment = JLabel.LEFT; }/*w w w .j ava 2 s. com*/ DefaultTableCellRenderer defaultTableCellRenderer = new DefaultTableCellRenderer(); defaultTableCellRenderer.setHorizontalAlignment(labelAlighnment); // defaultTableCellRenderer.setFont(tahoma); for (int columnIndex = 0; columnIndex < jTable.getColumnCount(); columnIndex++) { if (jTable.getModel().getColumnClass(columnIndex).equals(Boolean.class)) { jTable.getColumnModel().getColumn(columnIndex).setWidth(60); jTable.getColumnModel().getColumn(columnIndex).setMaxWidth(90); jTable.getColumnModel().getColumn(columnIndex).setMinWidth(10); jTable.getColumnModel().getColumn(columnIndex).setPreferredWidth(60); continue; } if (jTable.getModel().getColumnClass(columnIndex).equals(ImageIcon.class)) { continue; } jTable.getColumnModel().getColumn(columnIndex).setCellRenderer(defaultTableCellRenderer); } DefaultTableCellRenderer renderer; renderer = (DefaultTableCellRenderer) jTable.getTableHeader().getDefaultRenderer(); renderer.setHorizontalAlignment(headerAlighnment); jTable.getTableHeader().setDefaultRenderer(renderer); }
From source file:com.sec.ose.osi.ui.frm.main.manage.AddProjectTableModel.java
public void setColumnView(JTable table) { table.setShowVerticalLines(false);/*from w w w. jav a 2s .c o m*/ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setColumnSelectionAllowed(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); table.setRowHeight(30); JTableHeader header = table.getTableHeader(); header.setPreferredSize(new java.awt.Dimension(table.getTableHeader().getWidth(), 30)); header.setFont(new Font("Arial", Font.BOLD, 12)); header.setReorderingAllowed(false); TableColumnModel cm = table.getColumnModel(); TableColumn col = null; searchHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ISSELECT), ""); col = cm.getColumn(COL_ISSELECT); col.setHeaderRenderer(searchHeader); }
From source file:kg.apc.jmeter.vizualizers.SynthesisReportGui.java
/** * Main visualizer setup./*from ww w . jav a 2s. c om*/ */ private void init() { this.setLayout(new BorderLayout()); // MAIN PANEL JPanel mainPanel = new JPanel(); Border margin = new EmptyBorder(10, 10, 5, 10); mainPanel.setBorder(margin); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.add(JMeterPluginsUtils.addHelpLinkToPanel(makeTitlePanel(), WIKIPAGE)); // SortFilterModel mySortedModel = // new SortFilterModel(myStatTableModel); JTable myJTable = new JTable(model); myJTable.getTableHeader().setDefaultRenderer(new JMeterHeaderAsPropertyRenderer(COLUMNS_MSG_PARAMETERS)); myJTable.setPreferredScrollableViewportSize(new Dimension(500, 70)); RendererUtils.applyRenderers(myJTable, RENDERERS); JScrollPane myScrollPane = new JScrollPane(myJTable); this.add(mainPanel, BorderLayout.NORTH); this.add(myScrollPane, BorderLayout.CENTER); saveTable.addActionListener(this); JPanel opts = new JPanel(); opts.add(useGroupName, BorderLayout.WEST); opts.add(saveTable, BorderLayout.CENTER); opts.add(saveHeaders, BorderLayout.EAST); this.add(opts, BorderLayout.SOUTH); }
From source file:logdruid.ui.table.EventRecordingEditorTable.java
private void initColumnSizes(JTable theTable) { MyTableModel model = (MyTableModel) theTable.getModel(); TableColumn column = null;/*from w w w . ja v a 2 s . c o m*/ Component comp = null; int headerWidth = 0; int cellWidth = 0; TableCellRenderer headerRenderer = theTable.getTableHeader().getDefaultRenderer(); for (int i = 0; i < 6; i++) { column = theTable.getColumnModel().getColumn(i); comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; cellWidth = comp.getPreferredSize().width; if (DEBUG) { logger.info("Initializing width of column " + i + ". " + "headerWidth = " + headerWidth + "; cellWidth = " + cellWidth); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }