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:ru.codemine.pos.ui.windows.document.cheque.ChequeListWindow.java
public void showWindow(List<Cheque> chequeList) { tableModel = new ChequeListTableModel(chequeList); table.setModel(tableModel);//from w w w . j av a 2 s . c om TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(0).setMaxWidth(10); columnModel.getColumn(1).setMaxWidth(50); statusLabel.setText(" " + chequeList.size() + " ?"); setupSorter(); showWindow(); }
From source file:ru.codemine.pos.ui.windows.selector.PaymentTypeSelector.java
public void selectForMainWindow() { if (!actionListenersInit) setupActionListeners();//from w w w .ja v a 2s . c o m mainWindow.blockBarcodeInput(); tableModel = new PaymentTypesListTableModel(); table.setModel(tableModel); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(0).setMaxWidth(10); columnModel.getColumn(1).setMaxWidth(50); setTitle(" "); statusLabel.setText(" " + tableModel.getRowCount() + " ?"); setupSorter(); setVisible(true); table.setSelectedRow(0); }
From source file:ru.codemine.pos.ui.windows.users.UsersListWindow.java
@Override public void showWindow() { List<User> users = userService.getAllUsers(); tableModel.setUsersList(users);//from w ww. j a v a 2 s.c o m table.setModel(tableModel); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(0).setMaxWidth(10); columnModel.getColumn(1).setMaxWidth(10); if (!actionListenersInit) setupActionListeners(); statusLabel.setText(" " + users.size() + " ?"); setupSorter(); setVisible(true); }
From source file:GenderEditor.java
public TableCellEditorJComboBox() { Container pane = getContentPane(); pane.setLayout(new BorderLayout()); TableValues tv = new TableValues(); table = new JTable(tv); TableColumnModel tcm = table.getColumnModel(); TableColumn tc = tcm.getColumn(TableValues.GENDER); tc.setCellEditor(new GenderEditor()); JScrollPane jsp = new JScrollPane(table); pane.add(jsp, BorderLayout.CENTER); }
From source file:ru.codemine.pos.ui.windows.stores.StoresListWindow.java
@Override public void showWindow() { List<Store> stores = storeService.getAll(); tableModel = new StoresListTableModel(stores); table.setModel(tableModel);// w w w . j av a 2s. c o m TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(0).setMaxWidth(10); columnModel.getColumn(1).setMaxWidth(50); if (!actionListenersInit) setupActionListeners(); statusLabel.setText(" " + stores.size() + " ?"); setupSorter(); setVisible(true); }
From source file:ru.codemine.pos.ui.windows.stores.StoreWindow.java
@Override public void showWindow(Store store) { if (!actionListenersInit) setupActionListeners();//from w ww. j a v a 2 s. c o m this.store = store; setTitle(" - " + store.getName()); storeIdField.setText(store.getId() == null ? "" : store.getId().toString()); storeNameField.setText(store.getName()); table.setModel(new StoreStocksTableModel(store)); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(0).setMaxWidth(10); if ("".equals(store.getName())) { storeNameField.setEditable(false); } else { storeNameField.setEditable(true); } setVisible(true); }
From source file:edu.ku.brc.specify.utilapps.SetUpBuildDlg.java
/** * @param table/*from w w w . j a v a2 s. co m*/ */ public static void calcColumnWidths(JTable table) { JTableHeader header = table.getTableHeader(); TableCellRenderer defaultHeaderRenderer = null; if (header != null) { defaultHeaderRenderer = header.getDefaultRenderer(); } TableColumnModel columns = table.getColumnModel(); TableModel data = table.getModel(); int margin = columns.getColumnMargin(); // only JDK1.3 int rowCount = data.getRowCount(); int totalWidth = 0; for (int i = columns.getColumnCount() - 1; i >= 0; --i) { TableColumn column = columns.getColumn(i); int columnIndex = column.getModelIndex(); int width = -1; TableCellRenderer h = column.getHeaderRenderer(); if (h == null) h = defaultHeaderRenderer; if (h != null) // Not explicitly impossible { Component c = h.getTableCellRendererComponent(table, column.getHeaderValue(), false, false, -1, i); width = c.getPreferredSize().width; } for (int row = rowCount - 1; row >= 0; --row) { TableCellRenderer r = table.getCellRenderer(row, i); Component c = r.getTableCellRendererComponent(table, data.getValueAt(row, columnIndex), false, false, row, i); width = Math.max(width, c.getPreferredSize().width + 10); // adding an arbitray 10 pixels to make it look nicer } if (width >= 0) { column.setPreferredWidth(width + margin); // <1.3: without margin } else { // ??? } totalWidth += column.getPreferredWidth(); } }
From source file:Main.java
public void mouseMoved(MouseEvent evt) { JTableHeader header = (JTableHeader) evt.getSource(); JTable table = header.getTable(); TableColumnModel colModel = table.getColumnModel(); int vColIndex = colModel.getColumnIndexAtX(evt.getX()); TableColumn col = null;//from w ww .j av a 2s . c o m if (vColIndex >= 0) { col = colModel.getColumn(vColIndex); } if (col != curCol) { header.setToolTipText((String) tips.get(col)); curCol = col; } }
From source file:ru.codemine.pos.ui.windows.devices.barcodescanner.BarcodeScannerListWindow.java
@Override public void showWindow() { List<BarcodeScannerDevice> devices = barcodeScannerService.getAllScanners(); tableModel.setBarcodeScannerDevices(devices); table.setModel(tableModel);//from ww w . ja v a2 s . co m TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(0).setMaxWidth(10); columnModel.getColumn(1).setMaxWidth(10); columnModel.getColumn(2).setMaxWidth(50); if (!actionListenersInit) setupActionListeners(); statusLabel.setText(" " + devices.size() + " ?"); setupSorter(); setVisible(true); }
From source file:TableIt.java
public TableIt() { JFrame f = new JFrame(); TableModel tm = new MyTableModel(); final JTable table = new JTable(tm); TableColumnModel tcm = table.getColumnModel(); TableColumn column = tcm.getColumn(tcm.getColumnCount() - 1); TableCellRenderer renderer = new MyTableCellRenderer(); column.setCellRenderer(renderer);//from w w w .j a v a2 s .co m JButton selectionType = new JButton("Next Type"); selectionType.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean rowSet = table.getRowSelectionAllowed(); boolean colSet = table.getColumnSelectionAllowed(); boolean cellSet = table.getCellSelectionEnabled(); boolean setRow = !rowSet; boolean setCol = rowSet ^ colSet; boolean setCell = rowSet & colSet; table.setCellSelectionEnabled(setCell); table.setColumnSelectionAllowed(setCol); table.setRowSelectionAllowed(setRow); System.out.println("Row Selection Allowed? " + setRow); System.out.println("Column Selection Allowed? " + setCol); System.out.println("Cell Selection Enabled? " + setCell); table.repaint(); } }); JButton selectionMode = new JButton("Next Mode"); selectionMode.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ListSelectionModel lsm = table.getSelectionModel(); int mode = lsm.getSelectionMode(); int nextMode; String nextModeString; if (mode == ListSelectionModel.SINGLE_SELECTION) { nextMode = ListSelectionModel.SINGLE_INTERVAL_SELECTION; nextModeString = "Single Interval Selection"; } else if (mode == ListSelectionModel.SINGLE_INTERVAL_SELECTION) { nextMode = ListSelectionModel.MULTIPLE_INTERVAL_SELECTION; nextModeString = "Multiple Interval Selection"; } else { nextMode = ListSelectionModel.SINGLE_SELECTION; nextModeString = "Single Selection"; } lsm.setSelectionMode(nextMode); System.out.println("Selection Mode: " + nextModeString); table.repaint(); } }); JPanel jp = new JPanel(); jp.add(selectionType); jp.add(selectionMode); JScrollPane jsp = new JScrollPane(table); Container c = f.getContentPane(); c.add(jsp, BorderLayout.CENTER); c.add(jp, BorderLayout.SOUTH); f.setSize(300, 250); f.show(); }