List of usage examples for javax.swing JTable getTableHeader
public JTableHeader getTableHeader()
tableHeader
used by this JTable
. From source file:pcgen.gui2.dialog.CharacterHPDialog.java
private void initComponents() { setDefaultCloseOperation(DISPOSE_ON_CLOSE); Container pane = getContentPane(); pane.setLayout(new BorderLayout()); JTable table = new JTable(tableModel) { @Override//from w ww .java2s . c om public TableCellEditor getCellEditor(int row, int column) { if (column == 5) {//TODO: the max roll should be calculated in a different manner String hd = levels.getClassTaken(levels.getElementAt(row)).getHD(); int max = NumberUtils.toInt(hd); return new IntegerEditor(1, max); } else { return super.getCellEditor(row, column); } } }; table.setDefaultRenderer(JButton.class, new Renderer()); table.setDefaultEditor(JButton.class, new Editor()); table.setCellSelectionEnabled(false); table.setRowHeight(new IntegerEditor(1, 10).getPreferredSize().height); JTableHeader header = table.getTableHeader(); header.setReorderingAllowed(false); JScrollPane scrollPane = new JScrollPane(table); pane.add(scrollPane, BorderLayout.CENTER); Box box = Box.createHorizontalBox(); box.add(new JLabel("Total Hp:")); box.add(Box.createHorizontalStrut(3)); final ReferenceListener<Integer> hpListener = new ReferenceListener<Integer>() { @Override public void referenceChanged(ReferenceEvent<Integer> e) { totalHp.setText(e.getNewReference().toString()); } }; ReferenceFacade<Integer> hpRef = character.getTotalHPRef(); totalHp.setText(hpRef.get().toString()); hpRef.addReferenceListener(hpListener); box.add(totalHp); box.add(Box.createHorizontalStrut(5)); JButton button = new JButton("Reroll All"); button.setActionCommand("Reroll"); button.addActionListener(this); box.add(button); box.add(Box.createHorizontalGlue()); button = new JButton("Close"); button.setActionCommand("Close"); button.addActionListener(this); box.add(button); pane.add(box, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { //Make sure to remove the listeners so that the garbage collector can //dispose of this dialog and prevent a memory leak levels.removeHitPointListener(tableModel); character.getTotalHPRef().removeReferenceListener(hpListener); } }); Utility.installEscapeCloseOperation(this); }
From source file:pcgen.gui2.dialog.PostLevelUpDialog.java
private void initComponents() { setDefaultCloseOperation(DISPOSE_ON_CLOSE); Container pane = getContentPane(); pane.setLayout(new BorderLayout()); JTable table = new JTable(tableModel) { @Override/*w ww. java 2s . c o m*/ public TableCellEditor getCellEditor(int row, int column) { if (column == LevelTableModel.COL_ROLLED_HP && row < numLevels) {//TODO: the max roll should be calculated in a different manner String hd = levels.getClassTaken(levels.getElementAt(row + oldLevel)).getHD(); int max = NumberUtils.toInt(hd); return new SpinnerEditor(new SpinnerNumberModel(1, 1, max, 1)); } return super.getCellEditor(row, column); } @Override public TableCellRenderer getCellRenderer(int row, int column) { if (column == LevelTableModel.COL_ROLLED_HP && row < numLevels) { return new SpinnerRenderer(); } return super.getCellRenderer(row, column); } }; table.setCellSelectionEnabled(false); table.setRowHeight(new JSpinner().getPreferredSize().height); JTableHeader header = table.getTableHeader(); header.setReorderingAllowed(false); JScrollPane scrollPane = new JScrollPane(table); pane.add(scrollPane, BorderLayout.CENTER); Box box = Box.createHorizontalBox(); box.add(Box.createHorizontalGlue()); JButton button = new JButton(LanguageBundle.getString("in_close")); //$NON-NLS-1$ button.setMnemonic(LanguageBundle.getMnemonic("in_mn_close")); //$NON-NLS-1$ button.setActionCommand("Close"); //$NON-NLS-1$ button.addActionListener(this); box.add(button); pane.add(box, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { //Make sure to remove the listeners so that the garbage collector can //dispose of this dialog and prevent a memory leak levels.removeHitPointListener(tableModel); } }); Utility.installEscapeCloseOperation(this); }
From source file:pl.otros.logview.gui.actions.StartSocketListener.java
private LogImporterAndPort chooseLogImporter() { Collection<LogImporter> elements = AllPluginables.getInstance().getLogImportersContainer().getElements(); LogImporter[] importers = elements.toArray(new LogImporter[0]); String[] names = new String[elements.size()]; for (int i = 0; i < names.length; i++) { names[i] = importers[i].getName(); }//w w w.j a va 2s. c o m JComboBox box = new JComboBox(names); SpinnerNumberModel numberModel = new SpinnerNumberModel(50505, 1025, 65000, 1); JSpinner jSpinner = new JSpinner(numberModel); MigLayout migLayout = new MigLayout(); JPanel panel = new JPanel(migLayout); panel.add(new JLabel("Select log importer")); panel.add(box, "wrap"); panel.add(new JLabel("Select port")); panel.add(jSpinner, "span"); if (logReaders.size() > 0) { panel.add(new JLabel("Opened sockets"), "wrap, growx"); JTable jTable = new JTable(logReaders.size(), 2); jTable.getTableHeader().getColumnModel().getColumn(0).setHeaderValue("Log importer"); jTable.getTableHeader().getColumnModel().getColumn(1).setHeaderValue("Port"); int row = 0; for (SocketLogReader socketLogReader : logReaders) { jTable.setValueAt(socketLogReader.getLogImporter().getName(), row, 0); jTable.setValueAt(Integer.toString(socketLogReader.getPort()), row, 1); row++; } JScrollPane jScrollPane = new JScrollPane(jTable); panel.add(jScrollPane, "wrap, span"); } int showConfirmDialog = JOptionPane.showConfirmDialog(null, panel, "Choose log importer and port", JOptionPane.OK_CANCEL_OPTION); if (showConfirmDialog != JOptionPane.OK_OPTION) { return null; } return new LogImporterAndPort(importers[box.getSelectedIndex()], numberModel.getNumber().intValue()); }
From source file:utils.ZTransform.java
@Override public void actionPerformed(ActionEvent e) { List<CMatrix> loadedCMatrices = CoolMapMaster.getLoadedCMatrices(); if (loadedCMatrices == null || loadedCMatrices.isEmpty()) { Messenger.showWarningMessage("No datasets were imported.", "No data"); return;//from w w w .j a va 2s.co m } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JTable table = new JTable(); DefaultTableModel defaultTableModel = Utils.getDefaultTableModel(); table.setModel(defaultTableModel); table.getColumnModel().removeColumn(table.getColumnModel().getColumn(0)); table.getTableHeader().setReorderingAllowed(false); int returnVal = JOptionPane.showConfirmDialog(CoolMapMaster.getCMainFrame(), new JScrollPane(table), "Select data", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (returnVal == JOptionPane.OK_OPTION) { int[] selectedRows = table.getSelectedRows(); ArrayList<CMatrix> selectedMatrices = new ArrayList<CMatrix>(); for (int row : selectedRows) { int index = table.convertRowIndexToModel(row); try { String ID = table.getModel().getValueAt(index, 0).toString(); CMatrix mx = CoolMapMaster.getCMatrixByID(ID); if (mx != null) { selectedMatrices.add(mx); } } catch (Exception e) { } } //do createZTransform(selectedMatrices); } } }); }
From source file:VGL.SummaryChartUI.java
private void updateDisplay() { //find out which buttons have been selected ArrayList<Integer> selectedTraits = new ArrayList<Integer>(); for (int i = 0; i < manager.getTraitSet().length; i++) { if (traitCheckBoxes[i].isSelected()) { selectedTraits.add(i);//from w w w. java 2 s . c o m } } PhenotypeCount[] result = manager.calculateTotals(selectedTraits, sexCheckBox.isSelected()); String[] columnHeadings = { Messages.getInstance().getString("VGLII.Phenotype"), Messages.getInstance().getString("VGLII.Observed"), Messages.getInstance().getString("VGLII.Expected") }; data = new Object[result.length][3]; for (int i = 0; i < result.length; i++) { data[i][0] = Messages.getInstance().translateLongPhenotypeName(result[i].getPhenotype()); data[i][1] = result[i].getCount(); data[i][2] = ""; } //if none selected, the "phenotype" is "organism" if ((selectedTraits.size() == 0) && !sexCheckBox.isSelected()) data[0][0] = Messages.getInstance().getString("VGLII.Organism"); // set width of columns sensibly - find longest one int maxPhenoStringLength = 0; for (int i = 0; i < result.length; i++) { if (data[i][0].toString().length() > maxPhenoStringLength) maxPhenoStringLength = data[i][0].toString().length(); } int phenoStringWidth = maxPhenoStringLength * 8; JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); JTable table = new JTable(new SummaryDataTableModel(data, columnHeadings)) { //Implement table header tool tips. protected JTableHeader createDefaultTableHeader() { return new JTableHeader(columnModel) { public String getToolTipText(MouseEvent e) { String tip = null; java.awt.Point p = e.getPoint(); int index = columnModel.getColumnIndexAtX(p.x); int realIndex = columnModel.getColumn(index).getModelIndex(); return columnToolTips[realIndex]; } }; } }; table.setGridColor(Color.BLACK); table.setShowGrid(true); table.getColumnModel().getColumn(0).setPreferredWidth(phenoStringWidth); table.getModel().addTableModelListener(this); panel.add(table.getTableHeader()); panel.add(table); resultPanel.removeAll(); resultPanel.add(panel); resultPanel.revalidate(); repaint(); }
From source file:vista.promocion.DiagPromocion.java
private void configurarTabla(JTable tbl) { JViewport scroll = (JViewport) tbl.getParent(); int ancho = scroll.getWidth(); int anchoColumna = 0; TableColumnModel modeloColumna = tbl.getColumnModel(); TableColumn columnaTabla;//w w w .ja v a2 s .c o m for (int i = 0; i < tbl.getColumnCount(); i++) { columnaTabla = modeloColumna.getColumn(i); switch (i) { case 0: anchoColumna = (1 * ancho) / 100; break; case 1: anchoColumna = (20 * ancho) / 100; break; case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: anchoColumna = (5 * ancho) / 100; break; } columnaTabla.setPreferredWidth(anchoColumna); tbl.setColumnModel(modeloColumna); } tbl.getTableHeader().setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10)); tbl.getTableHeader().setBackground(java.awt.Color.WHITE); tbl.getTableHeader().setForeground(Color.BLACK); //Si le queremos cambiar el tamao a la tablita tbl.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10)); }
From source file:vista.ventas.DiagOrdenesDeCompra.java
private void configurarTabla(JTable tbl) { JViewport scroll = (JViewport) tbl.getParent(); int ancho = scroll.getWidth(); int anchoColumna = 0; TableColumnModel modeloColumna = tbl.getColumnModel(); TableColumn columnaTabla;// w ww . ja v a2 s .c o m for (int i = 0; i < tbl.getColumnCount(); i++) { columnaTabla = modeloColumna.getColumn(i); switch (i) { case 0: anchoColumna = (1 * ancho) / 100; break; case 1: anchoColumna = (20 * ancho) / 100; break; case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: anchoColumna = (5 * ancho) / 100; break; } columnaTabla.setPreferredWidth(anchoColumna); tbl.setColumnModel(modeloColumna); } tbl.getTableHeader().setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10)); tbl.getTableHeader().setBackground(java.awt.Color.WHITE); tbl.getTableHeader().setForeground(Color.BLACK); tbl.getTableHeader().setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 18)); //Si le queremos cambiar el tamao a la tablita tbl.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 18)); }
From source file:vista.ventas.DialogEntregas.java
private void configurarTabla(JTable tbl) { JViewport scroll = (JViewport) tbl.getParent(); int ancho = scroll.getWidth(); int anchoColumna = 0; TableColumnModel modeloColumna = tbl.getColumnModel(); TableColumn columnaTabla;/*from ww w . ja v a 2 s .c om*/ for (int i = 0; i < tbl.getColumnCount(); i++) { columnaTabla = modeloColumna.getColumn(i); switch (i) { case 0: anchoColumna = 1 / 100; break; case 1: anchoColumna = (20 * ancho) / 100; break; case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: anchoColumna = (5 * ancho) / 100; break; } columnaTabla.setPreferredWidth(anchoColumna); tbl.setColumnModel(modeloColumna); } tbl.getTableHeader().setBackground(java.awt.Color.WHITE); tbl.getTableHeader().setForeground(Color.BLACK); tbl.getTableHeader().setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 14)); //Si le queremos cambiar el tamao a la tablita tbl.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 14)); }