IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants Java Discussion :

[JTable] toolTips sur un tableau


Sujet :

Composants Java

  1. #1
    Membre éclairé
    Avatar de seiryujay
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    950
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 950
    Points : 722
    Points
    722
    Par défaut [JTable] toolTips sur un tableau
    Bonjour,

    J'ai récupéré un composant qui utilise comme renderer la classe suivante.
    J'aimerais afficher dans un toolTipText le contenu de la cellule sur laquelle se trouve le curseur.
    J'ai essayé de placer du setToolTipText() à 2 ou 3 endroits, mais ça ne donne rien...

    Quelqu'un voit-il où je dois le mettre?
    Merci!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
     
    public class TreeTableCellRenderer extends JTree implements TableCellRenderer {
    		/** Last table/tree row asked to renderer. */
    		protected int visibleRow;
     
     
    		public TreeTableCellRenderer(TreeModel model) {
    			super(model);
    		}
     
    		/**
                     * updateUI is overridden to set the colors of the Tree's renderer to
                     * match that of the table.
                     */
    		public void updateUI() {
    			super.updateUI();
    			// Make the tree's cell renderer use the table's cell selection
    			// colors.
    			TreeCellRenderer tcr = getCellRenderer();
    			if (tcr instanceof DefaultTreeCellRenderer) {
    				DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
     
    				// pour changer l'icone des feuilles
    //				dtcr.setLeafIcon(null);
     
    				// For 1.1 uncomment this, 1.2 has a bug that will cause an
    				// exception to be thrown if the border selection color is
    				// null.
    				// dtcr.setBorderSelectionColor(null);
    				dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
    				dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
     
    				// test tooltip : il affiche un tooltip mais pas rempli 
    				// et donc tout petit; et que sur l'arbre ici...
    //				dtcr.setToolTipText(dtcr.getText());
    			}
    		}
     
    		/**
                     * Sets the row height of the tree, and forwards the row height to the
                     * table.
                     */
    		public void setRowHeight(int rowHeight) {
    			if (rowHeight > 0) {
    				super.setRowHeight(rowHeight);
    				if (JTreeTable.this != null
    						&& JTreeTable.this.getRowHeight() != rowHeight) {
    					JTreeTable.this.setRowHeight(getRowHeight());
    				}
    			}
    		}
     
    		/**
                     * This is overridden to set the height to match that of the JTable.
                     */
    		public void setBounds(int x, int y, int w, int h) {
    			super.setBounds(x, 0, w, JTreeTable.this.getHeight());
    		}
     
    		/**
                     * Sublcassed to translate the graphics such that the last visible row
                     * will be drawn at 0,0.
                     */
    		public void paint(Graphics g) {
    			g.translate(0, -visibleRow * getRowHeight());
    			super.paint(g);
    		}
     
    		/**
                     * TreeCellRenderer method. Overridden to update the visible row.
                     */
    		public Component getTableCellRendererComponent(JTable table,
    				Object value, boolean isSelected, boolean hasFocus, int row,
    				int column) {
    			if (isSelected)
    				setBackground(table.getSelectionBackground());
    			else
    				setBackground(table.getBackground());
     
    			visibleRow = row;
    //			System.out.println("text : "+custom.getText());
    //			System.out.println("name : "+custom.getName());
    //			custom.setToolTipText(custom.getText());
    //			this.setToolTipText("toto");
    			return this;
    		}

  2. #2
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 840
    Points : 22 854
    Points
    22 854
    Billets dans le blog
    51
    Par défaut
    Par défaut les JTree n'emmettent pas d'infobulles.

    Eventuellement essaie de faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    ToolTipManager.sharedInstance().registerComponent(this);
    à la création. En tout ca c'est ce qu'il faut faire pourqu'un JTree normal se mette à afficher des infobulles, ça marchera peut-être avec un arbre dans une table.

    Voir http://java.sun.com/docs/books/tutor...ents/tree.html rubrique "Customizing a Tree's Display"

    Après, en usage JTree simple normal, c'est dans le code du TreeCellRenderer qu'il faut faire un setToolTipText() quoique qu'en surchargeant l'une des méthodes getToolTipText() de la classe JTree ca devrait marcher aussi.
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

  3. #3
    Membre éclairé
    Avatar de seiryujay
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    950
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 950
    Points : 722
    Points
    722
    Par défaut
    Euh moi en fait, c'est sur les cellules de la table que doivent apparaître les tooltips...

    Le composant que j'utilise est un JTreeTable qui utilise un arbre comme CellRenderer de la première colonne. Le reste est une JTable normale.

    Et j'aimerai afficher la valeur de la cellule sur laquelle je pointe (que ce soit une cellule contenant un noeud du JTree ou une case normale de la JTable)

  4. #4
    Membre éclairé
    Avatar de seiryujay
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    950
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 950
    Points : 722
    Points
    722
    Par défaut
    C'est bon, j'ai trouvé!
    Il sufit de redéfinir la méthode getToolTipText dans ma classe JTreeTable qui étend JTable.
    Ca donne ça dans mon cas :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
     
    public String getToolTipText(MouseEvent e) {
    	int row = 0;
    	int col = 0;
    	Point p = e.getPoint();
            row = rowAtPoint(p);
            col = columnAtPoint(p);
     
    	String tip = (String) getValueAt(row, col);
    	System.out.println(tip);
            return tip;
        }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. function sur un tableau
    Par bibi2607 dans le forum ASP
    Réponses: 9
    Dernier message: 17/02/2005, 09h54
  2. [débutant]ToolTip sur un Graphic2D
    Par pingoui dans le forum AWT/Swing
    Réponses: 23
    Dernier message: 21/01/2005, 09h34
  3. Réponses: 2
    Dernier message: 08/04/2004, 16h30
  4. Comment faire un Drag&Drop sur un tableau
    Par Stef.web dans le forum Composants VCL
    Réponses: 6
    Dernier message: 11/10/2003, 13h12
  5. [VBA-E] Dim dynamique sur un tableau
    Par Vince69 dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 12/12/2002, 13h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo