List of usage examples for javax.swing.table TableColumn TableColumn
public TableColumn(int modelIndex, int width)
null
renderer and a null
editor. From source file:DisplayModeModel.java
private void initComponents(Container c) { setContentPane(c);//from ww w . j a va 2s . co m c.setLayout(new BorderLayout()); // Current DM JPanel currentPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); c.add(currentPanel, BorderLayout.NORTH); JLabel current = new JLabel("Current Display Mode : "); currentPanel.add(current); currentPanel.add(currentDM); // Display Modes JPanel modesPanel = new JPanel(new GridLayout(1, 2)); c.add(modesPanel, BorderLayout.CENTER); // List of display modes for (int i = 0; i < COLUMN_WIDTHS.length; i++) { TableColumn col = new TableColumn(i, COLUMN_WIDTHS[i]); col.setIdentifier(COLUMN_NAMES[i]); col.setHeaderValue(COLUMN_NAMES[i]); dmList.addColumn(col); } dmList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); dmList.getSelectionModel().addListSelectionListener(this); modesPanel.add(dmPane); // Controls JPanel controlsPanelA = new JPanel(new BorderLayout()); modesPanel.add(controlsPanelA); JPanel controlsPanelB = new JPanel(new GridLayout(2, 1)); controlsPanelA.add(controlsPanelB, BorderLayout.NORTH); // Exit JPanel exitPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); controlsPanelB.add(exitPanel); exitPanel.add(exit); // Change DM JPanel changeDMPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); controlsPanelB.add(changeDMPanel); changeDMPanel.add(changeDM); controlsPanelA.add(new JPanel(), BorderLayout.CENTER); }
From source file:com.vgi.mafscaling.ClosedLoop.java
private JTable createAfrDataTable(JPanel panel, String tableName, int gridy) { final JTable afrTable = new JTable() { private static final long serialVersionUID = 6526901361175099297L; public boolean isCellEditable(int row, int column) { return false; };//from ww w . j a v a 2 s . c om }; DefaultTableColumnModel afrModel = new DefaultTableColumnModel(); final TableColumn afrColumn = new TableColumn(0, 250); afrColumn.setHeaderValue(tableName); afrModel.addColumn(afrColumn); JTableHeader lblAfrTableName = afrTable.getTableHeader(); lblAfrTableName.setColumnModel(afrModel); lblAfrTableName.setReorderingAllowed(false); DefaultTableCellRenderer headerRenderer = (DefaultTableCellRenderer) lblAfrTableName.getDefaultRenderer(); headerRenderer.setHorizontalAlignment(SwingConstants.LEFT); GridBagConstraints gbc_lblAfrTableName = new GridBagConstraints(); gbc_lblAfrTableName.insets = new Insets((gridy == 0 ? 0 : 5), 0, 0, 0); gbc_lblAfrTableName.anchor = GridBagConstraints.PAGE_START; gbc_lblAfrTableName.fill = GridBagConstraints.HORIZONTAL; gbc_lblAfrTableName.gridx = 0; gbc_lblAfrTableName.gridy = gridy; panel.add(lblAfrTableName, gbc_lblAfrTableName); afrTable.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { afrColumn.setWidth(afrTable.getWidth()); } }); afrTable.getTableHeader().setReorderingAllowed(false); afrTable.setColumnSelectionAllowed(true); afrTable.setCellSelectionEnabled(true); afrTable.setBorder(new LineBorder(new Color(0, 0, 0))); afrTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); afrTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); afrTable.setModel(new DefaultTableModel(AfrTableRowCount, AfrTableColumnCount)); Utils.initializeTable(afrTable, ColumnWidth); if (tableName.equals(Afr1TableName)) { Format[][] formatMatrix = { { new DecimalFormat("#"), new DecimalFormat("0.00") } }; NumberFormatRenderer renderer = (NumberFormatRenderer) afrTable.getDefaultRenderer(Object.class); renderer.setFormats(formatMatrix); } else if (tableName.equals(Afr2TableName)) { Format[][] formatMatrix = { { new DecimalFormat("#"), new DecimalFormat("0.00") }, { new DecimalFormat("#"), new DecimalFormat("#") } }; NumberFormatRenderer renderer = (NumberFormatRenderer) afrTable.getDefaultRenderer(Object.class); renderer.setFormats(formatMatrix); } GridBagConstraints gbc_afrTable = new GridBagConstraints(); gbc_afrTable.insets = new Insets(0, 0, 0, 0); gbc_afrTable.anchor = GridBagConstraints.PAGE_START; gbc_afrTable.gridx = 0; gbc_afrTable.gridy = gridy + 1; panel.add(afrTable, gbc_afrTable); excelAdapter.addTable(afrTable, true, false); return afrTable; }