Multiline tooltip for JComboBox items.

Hi, As the title suggests I'd like to create a multiline tooltip for items in a combobox list.
I have implemented a multiline tooltip renderer which works perfectly on any component except JComboBox items.
I have also implemented a ListCellRenderer for a combobox that enables tooltips for the combobox items. Also works perfectly, except that they are single line tooltips.
The tooltip text is read from an xml file, therefore I have no control on how long the line of text is. Most of the time the text also contains newlines.
This is the method (overridden from JComponent) added to a subclass of a component so that that component uses the MultiLineToolTip:
    public JToolTip createToolTip() {
        MultiLineToolTip tip = new MultiLineToolTip(this);
        tip.setComponent(this);
        return tip;
    }And this is the ListCellRenderer used on the combobox, so that items have (single-line) tooltips enabled:
    private class ToolTipEnabledComboBoxRenderer extends JLabel implements ListCellRenderer{
         public ToolTipEnabledComboBoxRenderer(){
              setOpaque(true);
         public Component getListCellRendererComponent(JList list,Object value,
                                                          int index,boolean isSelected,
                                                          boolean cellHasFocus) {
              String entry = (String)value;
              if (isSelected || cellHasFocus) {
                   this.setBackground(list.getSelectionBackground());
                   setForeground(list.getSelectionForeground());
              } else {
                   this.setBackground(list.getBackground());
                   setForeground(list.getForeground());
              this.setText(entry);
              if(isSelected || cellHasFocus){
                   if(constraint!=null &&combobox!=null &&
                               constraint.getType() == Constrained.CONTROLLED_VOCABULARY){
                        String tooltip = ((ControlledVocabulary)constraint).getEntryDescription(entry);
                        if(tooltip==null || tooltip.equals("")){
                             tooltip="";
                        list.setToolTipText(tooltip);
              return this;
    }It seems to me that what I have to do is subclass the list used by the combobox and override the createToolTip() method. But how can I set the list used by the combobox? As far as I know the only time I can access the list is in the getListCellRendererComponent() method of the ListCellRenderer, in which the list is a parameter.
Any ideas?
Don

Hello,
<p>Have you seen this one?</p>
Francois

Similar Messages

  • Multiline tooltips for jlist

    How to get different multiline tooltip for different cell of jlist

    There are two different questions here:
    1. To get a multi-line tooltip, use HTML, e.g. "<html>first line<p>second line"
    2. To get item-specific tooltip text in a JList, write your own class that implements ListCellRenderer, as discussed at http://java.sun.com/docs/books/tutorial/uiswing/components/list.html#renderer

  • MultiLine tooltip for the JList item

    Hi,
    I did the search for the multiline tooltip in this forum and
    I found the following link which is kind of what I am looking for
    http://www.codeguru.com/java/articles/122.shtml
    Since the item tooltip string could be very long (no limit), I would like to truncate it. The line sepearator cannot be based on the \n of
    the tooltip text. I am thinking to fix size the JTextArea to: row 4
    and columan 40, and put the tooltip text into it (igoring the \n)
    with the setLineWrap(true) and setWrapStyleWord(true).
    If the JTextArea line goes more than 3, the tooltip text should only
    display the first 3 lines of the JTextArea and append "..." at the end
    of the 3rd line. Is is possible? Or someone has better idea? Or if
    there is sample code out there doing similar thing?
    Thanks,
    Pin

    why not just use html?
    return "<html> sometext<br>line2<br>line3</html>";
    Of course you'll have to manually break the line up but it's not all
    that hard to write.
    Mark

  • Yone Tooltip for each item of select-list

    Could an

    To set the tooltip for each value selected from Drop Down list - means value is selected in drop down list and the mouse over on the field (i thought this way, if its not correct ignore the same.
    For the above case check the selected drop down value on change event and set the desired text as tooltip.
    For example
    if(xfa.event.newText == "One")
    this.assist.toolTip.value = "You Selected Choice " +xfa.event.newText;
    Thanks,
    Raghu.

  • ToolTip for JButton from JComboBox

    nice day,
    how can I set some ToolTip for JComboBox's button that contains arrow

    nice day,
    @ Darryl
    thank you, but if I understood your advice, then is that correct way?
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    import javax.swing.ToolTipManager;
    import javax.swing.border.EmptyBorder;
    import javax.swing.plaf.metal.MetalComboBoxButton;
    public class ToolTipCombo extends JFrame {
        private static final long serialVersionUID = 1L;
        private String comboBoxItems[] = {"item", "item"};
        private String toolTipForCombo = "ToolTip from JComboBox No : ";
        private final JPanel fatherPanel = new JPanel();
        private JComboBox cb = new JComboBox(comboBoxItems);
        private JComboBox cb1 = new JComboBox(comboBoxItems);
        private JComboBox cb2 = new JComboBox(comboBoxItems);
        private JComboBox cb3 = new JComboBox(comboBoxItems);
        public static boolean createNew = true;
        int iC = 0;
        public void makeUI() {
            ToolTipManager ttm = ToolTipManager.sharedInstance();
            ttm.setInitialDelay(0);
            ttm.setDismissDelay(10000);
            cb.setPreferredSize(new Dimension(150, 20));
            setToolTipJComboBoxJButtonUI(cb);
            cb1.setPreferredSize(new Dimension(150, 20));
            setToolTipJComboBoxJButtonUI(cb1);
            cb2.setPreferredSize(new Dimension(150, 20));
            setToolTipJComboBoxJButtonUI(cb2);
            cb3.setPreferredSize(new Dimension(150, 20));
            setToolTipJComboBoxJButtonUI(cb3);
            fatherPanel.setLayout(new GridLayout(5, 5));
            fatherPanel.add(cb);
            fatherPanel.add(cb1);
            fatherPanel.add(cb2);
            fatherPanel.add(cb3);
            fatherPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
            createNew = false;
            setLayout(new BorderLayout(5, 5));
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            add(fatherPanel, BorderLayout.CENTER);
            pack();
            setLocation(50, 50);
            setVisible(true);
        void setToolTipJComboBoxJButtonUI(JComboBox combo) {
            JComboBox toolTipComboButton = combo;
            Component[] comp = toolTipComboButton.getComponents();
            for (int i = 0; i < comp.length; i++) {
                if (comp[i] instanceof MetalComboBoxButton) {
                    iC++;
                    MetalComboBoxButton toolTipButton = (MetalComboBoxButton) comp;
    toolTipButton.setToolTipText(toolTipForCombo + iC);
    break;
    public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
    new ToolTipCombo().makeUI();

  • Unable to set tooltip for item (sap.ui.core.Item)

    sap.ui.core.Item does not have the property 'tooltip'. But it borrows 'tooltip' property and setTooltip( ), getTooltip( ) methods from sap.ui.core.Element.
    Still, if I set the tooltip for item, it is not reflected. What might be wrong?
    Consider the following piece of code for example:
    var item = new sap.ui.core.Item({text:'Item'});
      item.setTooltip('tooltip');
      var oCollection = new sap.ui.ux3.Collection({ items: item
      var oCollectionInspector = new sap.ui.ux3.CollectionInspector({
      'fitParent' : false,
      'collections' : [
      new sap.ui.ux3.Collection({
      'title' : 'My Accounts',
      'items' : [ item]
      oCollectionInspector.placeAt('content');

    Tooltip is applied on the Item, but it seems Collection Inspector set its own tooltip for the Item. You can do something like this to set your own tooltip,
    var item = new sap.ui.core.Item("myItem",{text:'Item'});
    var oCollectionInspector = new sap.ui.ux3.CollectionInspector({
      'fitParent' : false,
      'collections' : [
      new sap.ui.ux3.Collection({
      'title' : 'My Accounts',
      'items' : [ item]
      oCollectionInspector.placeAt('content');
      oCollectionInspector.onAfterRendering = function(){
           sap.ui.ux3.CollectionInspector.prototype.onAfterRendering.apply(this,arguments);
           $('#myItem').attr('title','My Tooltip');

  • How to set Font to the ToolTip in JComboBox

    Hi,
    I am having problem in setting font to the ToolTip for JComboBox.
    Help needed asap...
    TIA,
    CK

    From the Mail menu bar click Mail > Preferences then select the Fonts & Colors tab.
    You can reset fonts sizes from there.
    Another way to open Mail Preferences, with Mail running, press Command ,  (comma) on your keyboard.
    The Mavericks upgrade may have reset that data to factory settings.

  • Problem with setting tooltips for items of a JCombobox

    hi guys,
    I want to set tooltips for items of JComboBox & the code that i have written is given below , but the tooltip text is set for all the items of Nonitindustrycombo but the tooltips remain the same even for Nonitdesgcombo's items.
    Is that we need to refresh the ComboboxRenderer every time ?
    I am not able to trace out the exact reason for this,please if anyone can suggest me something regarding this would be of great use to me.
    class Searchpanel extends JPanel {
    String[] str = null;
    public SearchPanel(){
    Nonitindustrycombo.addItem("--Select--");
    ArrayList NonITindus = ERPModel.getAllNonitIndustry(); //gets all the items(strings) for Nonitindustrycombo
    for (Iterator iter = NonITindus.iterator(); iter.hasNext();) {
    String str = iter.next().toString();
    Nonitindustrycombo.addItem(str);
    SetTooltip(Nonitindustrycombo,NonITindus);
    Nonitdesgcombo.addItem("--Select---");
    ArrayList desg = ERPModel.getAllNonitDesg(); //gets all the items(strings) for Nonitdesgcombo
    for (Iterator iter = desg.iterator(); iter.hasNext();) {
    Nonitdesgcombo.addItem(iter.next());
    SetTooltip(Nonitdesgcombo,desg);
    class MyComboBoxRenderer extends BasicComboBoxRenderer
    public Component getListCellRendererComponent(JList list, Object value,
    int index, boolean isSelected,
    boolean cellHasFocus)
    if (isSelected)
    setBackground(list.getSelectionBackground());
    setForeground(list.getSelectionForeground());
    if (0 < (index))
    list.setToolTipText(str[index - 1]);
    else
    setBackground(list.getBackground());
    setForeground(list.getForeground());
    setFont(list.getFont());
    setText((value == null) ? "" : value.toString());
    return this;
    private void SetTooltip(JComboBox combo,ArrayList arr){
    str = (String []) arr.toArray (new String [arr.size ()]);
    combo.setRenderer(new MyComboBoxRenderer());
    public static void main(String[] args){
    new SearchPanel();
    Thanks ,
    vishal

    1) You where given a working example in your last posting on this topic. Compare your code with the working code to see whats different and fix it.
    2) The code you posted doesn't compile.
    3) You didn't use the "Code Formatting Tags" when you posted your code so it not readable.

  • How to implement tooltip for the list items for the particular column in sharepoint 2013

    Hi,
    I had created a list, How to implement tooltip for the list items for the particular column in SharePoint 2013.
    Any help will be appreciated

    We can use JavaScript or JQuery to show the tooltips. Refer to the following similar thread.
    http://social.technet.microsoft.com/forums/en/sharepointdevelopmentprevious/thread/1dac3ae0-c9ce-419d-b6dd-08dd48284324
    http://stackoverflow.com/questions/3366515/small-description-window-on-mouse-hover-on-hyperlink
    http://spjsblog.com/2012/02/12/list-view-preview-item-on-hover-sharepoint-2010/

  • Setting ToolTips for items which are disabled.

    Folks,
    No offence meant if this is a repeat.
    I have a JPopupMenu with Action as its components.
    1) I have disabled certain menu items to false.
    2) I would like to use a ToolTipText to show a message 'You have no permission'
    when the user hovers over the menu items which are disabled/set to false
    3) I wrote my own ToolTipText,but what is happening is that I am getting the tool tip text
    for all menu items.
    Please can anyone help me in how to get tooltiptext for menu items which are enabled to false?
    Help much appreciated
    // JPopupMenu
    JPopupMenu pm = new JPopupMenu();
    // Add Action
    pm.add(new GraphAction());      
    pm.add(new DescendantsAction());
    pm.add(new DebugAction()).setEnabled(false);
    ToolTipTextForMenuItems.setToolTipForIndividualItem(pm.getComponent()) // Does not display any Tool Tip.
    pm.add(new ResetAction()).setEnabled(false);
    ToolTipTextForMenuItems.setToolTipTextForMenuItem(pm); // Shows ToolTipText for all menu items (disabled and enabled)
    ToolTip Code
    public class ToolTipTextForMenuItems {
    private static final String TOOL_TIP_TEXT = "You have no permission";
         public static void setToolTipTextForMenuItem(JPopupMenu popupMenu){
                 for (int i=0; i<popupMenu.getComponentCount(); i++){
                    Component c = popupMenu.getComponent(i);
                    if (c instanceof JComponent) {
                              ((JComponent)c).setToolTipText(TOOL_TIP_TEXT);
         public static void setToolTipForIndividualItem(Component c){
               if (c instanceof JComponent) {
                         ((JComponent)c).setToolTipText(TOOL_TIP_TEXT);
    }

    Yes,I have looked at the Abstract Action code sent in
    I have not used Action and Abstract Action before,hence if you can/could just
    modify this as per my requirement,then I can enhance on this.
    No offence meant for the above
    Thanks

  • How to make a tooltip for incoming list items

    Hi,
    I am trying to make a tooltip with JQuery for incoming list items. People will enter some text in a textfield en those values will be added to a list. I want to make a tooltip for every list item that will be added to the list. I want the text that people fill in in the textfield to be added in the tooltip, is this possible? And how can I do this? Thanks! This is what I have so far..
    <input type="text" id="input" placeholder="Voer item in" /> <button id="button">Toevoegen</button>
    <div id="tooltip"></div>
    $(document).ready(function(e) {
      $('#button').on('click', function (){
      var toevoegen = $('#input').val();
      var verwijderen = '<a href = "#" class = "verwijderen">Verwijderen</a>'
      <!--add list item-->
      $('#boodschappenlijst').prepend('<li>' + toevoegen + '' + '\t' + verwijderen + '</li>');
    <!--remove list item-->
    $('#boodschappenlijst').on('click', '.verwijderen', function(){
      $(this).parent('li').remove();
    <!-textfield empty-->
    $('#input').on('click', function (){
      $(this).val('')
    $('#boodschappenlijst').hover(
    function (){
      $('#tooltip').css('display', 'block')
    function (){
      $('#tooltip').css('display', 'none')
    #tooltip {
      position: absolute;
      top: 100px;
      right: 300px;
      border: 1px solid #000000;
      border-radius: 5px;
      color: black;
      width: 100px;
      display: none;
    The tooltip appears, but I want the text that people fill in in the textfield to be added in the tooltip

    Hi,
    I am trying to make a tooltip with JQuery for incoming list items. People will enter some text in a textfield en those values will be added to a list. I want to make a tooltip for every list item that will be added to the list. I want the text that people fill in in the textfield to be added in the tooltip, is this possible? And how can I do this? Thanks! This is what I have so far..
    <input type="text" id="input" placeholder="Voer item in" /> <button id="button">Toevoegen</button>
    <div id="tooltip"></div>
    $(document).ready(function(e) {
      $('#button').on('click', function (){
      var toevoegen = $('#input').val();
      var verwijderen = '<a href = "#" class = "verwijderen">Verwijderen</a>'
      <!--add list item-->
      $('#boodschappenlijst').prepend('<li>' + toevoegen + '' + '\t' + verwijderen + '</li>');
    <!--remove list item-->
    $('#boodschappenlijst').on('click', '.verwijderen', function(){
      $(this).parent('li').remove();
    <!-textfield empty-->
    $('#input').on('click', function (){
      $(this).val('')
    $('#boodschappenlijst').hover(
    function (){
      $('#tooltip').css('display', 'block')
    function (){
      $('#tooltip').css('display', 'none')
    #tooltip {
      position: absolute;
      top: 100px;
      right: 300px;
      border: 1px solid #000000;
      border-radius: 5px;
      color: black;
      width: 100px;
      display: none;
    The tooltip appears, but I want the text that people fill in in the textfield to be added in the tooltip

  • Tooltips for individual JCombo items

    I am currently trying to extend a JCombo used for searches in a database to also contain Tooltips (fetched from Database just like the JCombo items).
    if(wipbinData!=null)
    for(int i=0;i<wipbinData.length;i++)
    directCRcombobox.addItem(wipbinData[0]);
    directCRcombobox.setToolTipText(wipbinData[i][1]); //here I need not to make tooltip work only on JCombo in general but on specific ceels.
    All tips on getting tooltips on single items in the combobox would be appreciated.

    I tried to look at solving the extra information need with the tooltips. But as that turned out to be too tricky I instead added the extra information after the main info in the combobox. Then I fixed my query by using stringtokenizer to get only the first text for the query.
    But thanks for the answer anyway

  • JCombox clicked shows dropdown, show tooltip for the dropdown

    Hi,
    I want to provide the tooltip for the dropdown of JCombobox for the whole or tooltip to the item where you move the mouse but not click.
    thanx

    Another note.. just found out that it doesnt work with Windows Look And feel... if i use the default, everythings just fine.. Her is the code: What am I doing wrong?
         private class UccComboBoxRenderer extends BasicComboBoxRenderer
              public Component getListCellRendererComponent(
                   JList list,
                   Object value,
                   int index,
                   boolean isSelected,
                   boolean cellHasFocus)
                   if (isSelected)
                        setBackground(list.getSelectionBackground());
                        setForeground(list.getSelectionForeground());
                        if (-1 < index)
                             list.setToolTipText(value.toString());
                   else
                        setBackground(list.getBackground());
                        setForeground(list.getForeground());
                   setText((value == null) ? "" : value.toString());
                   return this;
         }

  • Associate Action with jcombobox item

    Is it possible to associate a particular Action with a jcombobox item (for example using setAction()). When the user selects a particular item of jcombobox, the Action must be triggered.
    regards,
    Nirvan.

    Hi,
    You can associate a particular action with a JComboBox. As per my understanding u can add one action perfrom action to combobox or itemStateChanged action
    if u add action perform action, u need to add the following method to ur logic.
    JComboBox combobox=new JComboBox();
        combobox.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
             JComboBox combo = (JComboBox)evt.getSource();
                if(combo.getSelectedItem().equals("LOCATION")) {
                A a = new A();
                a.show();
            } else if(combo.getSelectedItem().equals("HOUSE")) {
                B b= new B();
                b.show();
            });if action is ItemStateChanged then add the following method.
    combobox.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt) {
                    and write your logic here which one needs to be triggered when this action performed.
            });Hope this will help to you....
    Thanks & Regards,
    Maadhav..

  • Chart legend : adding tooltip on each item

    Hi,
    My app displays a simple Linechart and its legend. I'm
    surprised to see that the Legend component doesn't provide many
    possibilities in accessing each of the items that compose it.
    First, I'd like to add a tooltip on each item of the legend.
    Then I would like to display a checkbox in front of every marker,
    to display/hide the corresponding item in the Linechart.
    One way could be to extend the Legend item (about this I
    found
    this
    nice - yet complicated - example), but I'd really like to know
    if there is a more simpe way to achieve it. As the Legend component
    is very dependant from its dataprovider, maybe I'd rather create my
    own custom legend, using my chart's values ?
    Any help will be appreciated ! Popop ./.

    les_paulde wrote:
    wow, thanks for your swift reply! This definitely solved my problem and I can now run the query. The code turned out as follows:
    String convList = listI.toString();
    convList = convList.replace("[", "(\"");
    convList = convList.replace("]", "\")");
    convList = convList.replaceAll(",", "\",");
    convList = convList.replaceAll(" ", " \"");
    And what happens if the String representation of the object in your list contains one of the characters you're replacing? It will go awfully wrong!
    This is safer:
    public static String asString(List<?> list) {
        StringBuilder b = new StringBuilder();
        b.append('(');
        for(int i = 0; i < list.size(); i++) {
            b.append('"').append(list.get(i)).append('"');
            if(i < list.size()-1) b.append(", ");
        return b.append(')').toString();
    System.out.println(asString(listI));

Maybe you are looking for

  • Used PCUI navigation to follow up a new opportunity, but it doesn't work.

    Hello, We faced a authorization problem with PCUI Navigation. We have configured a navigation for following up other opportunity. If the user has the SAP_ALL and SAP_NEW authorization, the navigation can work. But we changed the user authorization, t

  • Layout issue in Oracle rdf

    Hi Experts, I am facing a strange issue in oracle rdf reports. Requesting an assistance from you. I have a report which displays the vendor information. For all the vendors the layout is working fine for me, but for one particular vendor the vendor n

  • Using -classpath "@c:/temp/foo.tmp" instead of whole path

    We are using WLS 6.0 and beasvc to start the server as an NT service. Within the registry for the service, there is a cmdline value that we would like to substitute the whole classpath settings for just a file that contains the information. In a prev

  • Incoming Payment Fast Entry

    Hi Can you tell me the easiest way that the users can process an incoming payment against a customer i.e. DR Bank CR Customer this could either be a payment on account, or be allocated to specific open items at a later date.  The users are used to en

  • What Should I Download To Use The Oracle 9i?

    I was told that the Oracle 9i and above are free for download. I would like to use the Oracle in my personal machine. I went to the Oracle website and saw lots of options. I did not know which one to select to download. For example, there are many op