List of usage examples for javax.swing JTable getModel
public TableModel getModel()
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 ww . j a va2s . co 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(); }