List of usage examples for javax.swing.table JTableHeader JTableHeader
public JTableHeader(TableColumnModel cm)
JTableHeader
which is initialized with cm
as the column model. From source file:Main.java
public Main() { super(new GridLayout(1, 0)); JTable table = new JTable(new MyTableModel()) { //Implement table cell tool tips. public String getToolTipText(MouseEvent e) { String tip = null;/* w w w . ja v a 2 s .c om*/ java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); int colIndex = columnAtPoint(p); int realColumnIndex = convertColumnIndexToModel(colIndex); if (realColumnIndex == 2) { //Sport column tip = "This person's favorite sport to " + "participate in is: " + getValueAt(rowIndex, colIndex); } else if (realColumnIndex == 4) { //Veggie column TableModel model = getModel(); String firstName = (String) model.getValueAt(rowIndex, 0); String lastName = (String) model.getValueAt(rowIndex, 1); Boolean veggie = (Boolean) model.getValueAt(rowIndex, 4); if (Boolean.TRUE.equals(veggie)) { tip = firstName + " " + lastName + " is a vegetarian"; } else { tip = firstName + " " + lastName + " is not a vegetarian"; } } else { //You can omit this part if you know you don't //have any renderers that supply their own tool //tips. tip = super.getToolTipText(e); } return tip; } //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.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true); //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this panel. add(scrollPane); }
From source file:components.TableToolTipsDemo.java
public TableToolTipsDemo() { super(new GridLayout(1, 0)); JTable table = new JTable(new MyTableModel()) { //Implement table cell tool tips. public String getToolTipText(MouseEvent e) { String tip = null;/* w w w . j a va 2 s . com*/ java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); int colIndex = columnAtPoint(p); int realColumnIndex = convertColumnIndexToModel(colIndex); if (realColumnIndex == 2) { //Sport column tip = "This person's favorite sport to " + "participate in is: " + getValueAt(rowIndex, colIndex); } else if (realColumnIndex == 4) { //Veggie column TableModel model = getModel(); String firstName = (String) model.getValueAt(rowIndex, 0); String lastName = (String) model.getValueAt(rowIndex, 1); Boolean veggie = (Boolean) model.getValueAt(rowIndex, 4); if (Boolean.TRUE.equals(veggie)) { tip = firstName + " " + lastName + " is a vegetarian"; } else { tip = firstName + " " + lastName + " is not a vegetarian"; } } else { //You can omit this part if you know you don't //have any renderers that supply their own tool //tips. tip = super.getToolTipText(e); } return tip; } //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.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true); //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this panel. add(scrollPane); }
From source file:TableToolTipsDemo.java
public TableToolTipsDemo() { super(new GridLayout(1, 0)); JTable table = new JTable(new MyTableModel()) { //Implement table cell tool tips. public String getToolTipText(MouseEvent e) { String tip = null;//from ww w .ja v a2 s .c om java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); int colIndex = columnAtPoint(p); int realColumnIndex = convertColumnIndexToModel(colIndex); if (realColumnIndex == 2) { //Sport column tip = "This person's favorite sport to " + "participate in is: " + getValueAt(rowIndex, colIndex); } else if (realColumnIndex == 4) { //Veggie column TableModel model = getModel(); String firstName = (String) model.getValueAt(rowIndex, 0); String lastName = (String) model.getValueAt(rowIndex, 1); Boolean veggie = (Boolean) model.getValueAt(rowIndex, 4); if (Boolean.TRUE.equals(veggie)) { tip = firstName + " " + lastName + " is a vegetarian"; } else { tip = firstName + " " + lastName + " is not a vegetarian"; } } else { //You can omit this part if you know you don't //have any renderers that supply their own tool //tips. tip = super.getToolTipText(e); } return tip; } //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.setPreferredScrollableViewportSize(new Dimension(500, 70)); //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this panel. add(scrollPane); }
From source file:com.att.aro.ui.model.ImageBPTable.java
/** * Returns a default table header for the DataTable. * /*from w w w. j av a2s . c om*/ * @return A JTableHeader object with default properties. */ @Override public JTableHeader createDefaultTableHeader() { return new JTableHeader(columnModel) { private static final long serialVersionUID = 1L; @Override public String getToolTipText(MouseEvent mEvent) { int column = columnAtPoint(mEvent.getPoint()); // Locate the renderer under the event location if (column != -1) { TableColumn aColumn = columnModel.getColumn(column); Object tip = aColumn.getHeaderValue(); if (tip != null) { return tip.toString(); } } return null; } }; }
From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java
private void makeCustomTableHeader(TableColumnModel columnModel) { JTableHeader h = new JTableHeader(columnModel) { public String getToolTipText(MouseEvent e) { if (isHasColumnHeaderPopup()) { int col = columnAtPoint(e.getPoint()); Field f = ((SpreadSheetModel) getModel()).getFieldInNonTranslatedColumn(col + 1); if (f != null) return "<html>" + f.getName() + "<br>" + Messages.getString("Text.rightClickToInsertRemoveColumns") + "</html>"; }// w w w . ja v a 2s. co m return super.getToolTipText(e); } }; setTableHeader(h); }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccSwing.CFAccSwingAccountConfigFinderJPanel.java
protected JTableHeader createDefaultTableHeader() { if (dataTableHeader == null) { dataTableHeader = new JTableHeader(getDataColumnModel()); dataTableHeader.setResizingAllowed(true); dataTableHeader.setTable(dataTable); }//w ww . j a v a 2 s. c om return (dataTableHeader); }
From source file:org.executequery.gui.resultset.ResultSetTable.java
protected JTableHeader createDefaultTableHeader() { return new JTableHeader(columnModel) { public String getToolTipText(MouseEvent e) { if (getModel() instanceof TableSorter) { TableSorter model = (TableSorter) getModel(); if (model.getTableModel() instanceof ResultSetTableModel) { ResultSetTableModel resultSetTableModel = (ResultSetTableModel) model.getTableModel(); Point point = e.getPoint(); int index = columnModel.getColumnIndexAtX(point.x); int realIndex = columnModel.getColumn(index).getModelIndex(); return resultSetTableModel.getColumnNameHint(realIndex); }//from ww w. j a va2 s . c om } return super.getToolTipText(e); } }; }
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);// ww w. j a va 2 s. c om } } 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(); }