Example usage for javax.swing JTable setToolTipText

List of usage examples for javax.swing JTable setToolTipText

Introduction

In this page you can find the example usage for javax.swing JTable setToolTipText.

Prototype

@BeanProperty(bound = false, preferred = true, description = "The text to display in a tool tip.")
public void setToolTipText(String text) 

Source Link

Document

Registers the text to display in a tool tip.

Usage

From source file:com.github.lindenb.jvarkit.tools.bamviewgui.BamFileRef.java

private static JTable createTable(TableModel m) {
    JTable t = new JTable(m) {
        @Override//w  w w.j  ava 2s  .c  o m
        public String getToolTipText(MouseEvent event) {
            JTable t = (JTable) event.getSource();
            int x = t.rowAtPoint(event.getPoint());
            if (x == -1)
                return null;
            int y = t.columnAtPoint(event.getPoint());
            if (y == -1)
                return null;
            Object o = t.getValueAt(x, y);
            if (o == null)
                return null;
            return String.valueOf(o);
        }

    };
    t.setToolTipText("");
    t.setShowVerticalLines(false);
    DefaultTableCellRenderer render = new DefaultTableCellRenderer() {
        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (!isSelected && !hasFocus)
                this.setBackground(row % 2 == 0 ? color1 : color2);
            if (value != null && value instanceof Boolean) {
                if (Boolean.TRUE.equals(value))
                    this.setText("\u2612");
                else if (Boolean.FALSE.equals(value))
                    this.setText("");
            }
            return c;
        }
    };
    render.setOpaque(true);
    for (int i = 0; i < t.getColumnModel().getColumnCount(); ++i) {
        t.getColumnModel().getColumn(i).setCellRenderer(render);
    }
    return t;
}

From source file:org.openconcerto.erp.core.finance.accounting.ui.PlanComptableGPanel.java

public JTable creerJTable(ClasseCompte ccTmp) { // NO_UCD

    final PlanComptableGModel model;
    if (this.radioCompteDeveloppe.isSelected()) {
        model = new PlanComptableGModel(ccTmp, 3);
    } else if (this.radioCompteAbrege.isSelected()) {
        model = new PlanComptableGModel(ccTmp, 2);
    } else {//ww  w  . ja va  2 s  .  com
        model = new PlanComptableGModel(ccTmp, 1);
    }

    final JTable table = new JTable(model) {
        public JToolTip createToolTip() {
            JMultiLineToolTip t = new JMultiLineToolTip();
            t.setFixedWidth(500);
            return t;
        }
    };

    table.getColumnModel().getColumn(0).setCellRenderer(new PlanComptableCellRenderer(0));
    table.getColumnModel().getColumn(1).setCellRenderer(new PlanComptableCellRenderer(0));

    // TODO calcul de la taille de la colone numero de compte
    table.getColumnModel().getColumn(0).setMaxWidth(90);

    table.getTableHeader().setReorderingAllowed(false);

    table.addMouseMotionListener(new MouseMotionAdapter() {
        int lastRow = -1;

        public void mouseMoved(final MouseEvent e) {

            final Point p = new Point(e.getX(), e.getY());

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    final int row = table.rowAtPoint(p);
                    if (lastRow != row) {
                        lastRow = row;
                        String strTmp = ((Compte) (model.getComptes().get(lastRow))).getInfos();

                        if (strTmp.length() != 0) {
                            table.setToolTipText(strTmp);
                        } else {
                            table.setToolTipText(null);
                        }

                    }
                }
            });

        }
    });

    if (this.actionClickDroit != null) {
        // System.out.println("Ajout menu droit");
        table.addMouseListener(new MouseAdapter() {

            public void mousePressed(MouseEvent e) {

                if (e.getButton() == MouseEvent.BUTTON3) {
                    actionDroitTable(e, table);
                }
            }
        });
    }

    // Enable row selection (default)
    /**
     * table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true);
     * 
     * table.setSelectionMode(table.getSelectionModel().MULTIPLE_INTERVAL_SELECTION);
     */

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            int selectedRow = table.getSelectedRow();
            if (selectedRow < 0) {
                // Pas de selection
                textInfos.setText("Pas de compte slctionn");
            } else {
                textInfos.setText(((Compte) (model.getComptes().get(selectedRow))).getInfos());
            }
        }
    });

    return table;
}