e776. 设置JList组件项的提示语

   // Create a list, overriding the getToolTipText() method
    String[] items = {"A", "B", "C", "D"};
    JList list = new JList(items) {
        // This method is called as the cursor moves within the list.
        public String getToolTipText(MouseEvent evt) {
            // Get item index
            int index = locationToIndex(evt.getPoint());
    
            // Get item
            Object item = getModel().getElementAt(index);
    
            // Return the tool tip text
            return "tool tip for "+item;
        }
    };

 

Related Examples
posted @ 2018-09-06 08:49  borter  阅读(139)  评论(0编辑  收藏  举报