Scrollable JFrame as a ToolTip

Hi,
I have a lot of information in HTML format that I display as a tooltip for my swing app.
Since this is a lot of information, not everything is being visible once the tooltip appears.
I was wondering if there is a way to override the tooltip component so that I can display a JFrame with possibly a JScrollPane with a JTextArea in it. I got this idea from Eclipse IDE where we get tool tip like information as java documentation for any particular component in the code when we do a moseover it. I really like the idea of it being focussable upon pressing F2 and then we get a immovable tooltip which looks like a Scrollable text area which doesnt disappear upon clicking. Also it allows text highlighting and copying from it. I am trying to create something on Eclipse's tooltip lines for my application. Any leads would be helpful.
Thanks.

It is possible to override the tooltip to display another component. Just search this forum, you are sure to find something.
You could also implement your own JWIndow component and place in it anything you want and just show this on your components when the mouse hovers over it for a few seconds. It is should probably be simpler to achieve than trying to re-write the tooltip component, IMHO
ICE

Similar Messages

  • Scrollable tooltip

    JScrollableToolTip
    The code of this scrollable tooltip contains a "main"-method for testing and for showing how to use "JScrollableToolTip".
    NOTE for tooltip in a JTable:
    When we want to use "JScrollableToolTip" for the cells of a JTable,
    we must know, that the cell renderer is only indirectly concerned.
    Primarily it's the JTable which is responsile for the tooltip. JTable uses only the tooltip text of the renderer.
    Thus we must override JTable #createTooltip() to return an instance of "JScrollableToolTip"
    and not the createTooltip-method of the renderer component (it is nether called).
    We may also need to override getToolTipLocation if the tooltip is outside the row height.
    * JScrollableToolTip.java
    import java.awt.*;
    import javax.swing.*;
    public class JScrollableToolTip extends JToolTip {
        private JTextArea tipArea;
        /** Creates a tool tip. */
        public JScrollableToolTip(final int width, final int height) {
            setPreferredSize(new Dimension(width, height));
            setLayout(new BorderLayout());
            tipArea = new JTextArea();
            tipArea.setLineWrap(true);
            tipArea.setWrapStyleWord(true);
            tipArea.setEditable(false);
            tipArea.setBackground(new Color(255,255,204));
            add(new JScrollPane(tipArea));
        @Override
        public void setTipText(final String tipText) {
            String oldValue = this.tipArea.getText();
            tipArea.setText(tipText);
            tipArea.setCaretPosition(0);
            firePropertyChange("tiptext", oldValue, tipText);
        @Override
        public String getTipText() {
            return tipArea == null ? "" : tipArea.getText();
        @Override
        protected String paramString() {
            String tipTextString = (tipArea.getText() != null ? tipArea.getText() : "");
            return super.paramString() +
                    ",tipText=" + tipTextString;
        //for testing only:
        public static void main(final String args[]) {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(300, 100);
            f.setLocationRelativeTo(null);
            ToolTipManager.sharedInstance().setDismissDelay(30000);
            JButton button = new JButton("Used to display...") {
                @Override
                public JToolTip createToolTip() {
                    JScrollableToolTip tip = new JScrollableToolTip(200, 80);
                    tip.setComponent(this);
                    return tip;
            button.setToolTipText("Used to display a 'Tip' for a Component. " +
                    "Typically components provide api to automate the process of " +
                    "using ToolTips. For example, any Swing component can use the " +
                    "JComponent  setToolTipText method to specify the text for a standard tooltip.");
            f.add(button);
            f.setVisible(true);
    }{code}
    Edited by: Andre_Uhres on Nov 26, 2008 11:43 AM
    We may also need to override getToolTipLocation if the tooltip is outside the row height.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Torgil wrote:
    It would be neat if you could tie this to the mouse scroll wheel, so that you can scroll even when the mouse is still over the source component.Godd idea, thanks. I will try it.
    EDIT: here the new version with the suggested feature:
    * JScrollableToolTip.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class JScrollableToolTip extends JToolTip implements MouseWheelListener {
        private JTextArea tipArea;
        private JScrollPane scrollpane;
        private JComponent comp;
        /** Creates a tool tip. */
        public JScrollableToolTip(final int width, final int height) {
            this(width, height, null);
        private JScrollableToolTip(final int width, final int height, final JComponent comp) {
            this.comp = comp;
            setPreferredSize(new Dimension(width, height));
            setLayout(new BorderLayout());
            tipArea = new JTextArea();
            tipArea.setLineWrap(true);
            tipArea.setWrapStyleWord(true);
            tipArea.setEditable(false);
            tipArea.setBackground(new Color(255, 255, 204));
            scrollpane = new JScrollPane(tipArea);
            add(scrollpane);
            if(comp != null){
                comp.addMouseWheelListener(this);
        public void mouseWheelMoved(final MouseWheelEvent e) {
            scrollpane.dispatchEvent(e);
            MouseEvent e2 = new MouseEvent(comp, MouseEvent.MOUSE_MOVED, 0, 0, 0, 0, 0, false);
            comp.dispatchEvent(e2);
        @Override
        public void setTipText(final String tipText) {
            String oldValue = this.tipArea.getText();
            tipArea.setText(tipText);
            tipArea.setCaretPosition(0);
            firePropertyChange("tiptext", oldValue, tipText);
        @Override
        public String getTipText() {
            return tipArea == null ? "" : tipArea.getText();
        @Override
        protected String paramString() {
            String tipTextString = (tipArea.getText() != null ? tipArea.getText() : "");
            return super.paramString() +
                    ",tipText=" + tipTextString;
        //for testing only:
        public static void main(final String args[]) {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(300, 100);
            f.setLocationRelativeTo(null);
            ToolTipManager.sharedInstance().setDismissDelay(0000);
            JButton button = new JButton("Used to display...") {
                @Override
                public JToolTip createToolTip() {
                    JScrollableToolTip tip = new JScrollableToolTip(200, 80, this);
                    tip.setComponent(this);
                    return tip;
            button.setToolTipText("Used to display a 'Tip' for a Component. " +
                    "Typically components provide api to automate the process of " +
                    "using ToolTips. For example, any Swing component can use the " +
                    "JComponent  setToolTipText method to specify the text for a standard tooltip.");
            f.add(button);
            f.setVisible(true);
    }Edited by: Andre_Uhres on Nov 27, 2008 6:23 PM
    Edited by: Andre_Uhres on Nov 28, 2008 1:37 PM
    I tried adding code to reset the DismissDelay on mouseWheelMoved.
    Edited by: Andre_Uhres on Nov 28, 2008 1:52 PM
    If you have any suggestions, please write to my email address, or else I will not be able edit the code any more.

  • How to make JFrame scrollable?

    How can I make a JFrame scrollable? So that when I resize the JFrame to a smaller size the contents remain accessible? The way it is now is that when I resize a JFrame I can't access the components that fall out of the window (I'm using absolute component positioning within the JFrame). I thought adding two scrollbars to take care of this would be easy, but so far I haven't been able to get it right. Any suggestions would be appreciated.

    Why dont you put all your components in a JPanel, add a scrollpane to it and then add that JPanel to
    ur JFrame.
    += KRR

  • How to add tooltip to jframe title?

    hi all
    does anyone knows how can i set tooltip for jframe title?
    thanks

    Since it's a slow Saturday and I'm in a good mood...import darrylbu.util.SwingUtils;
    import javax.swing.*;
    public class FrameTitleToolTip {
       public static void main(String[] args) {
          JFrame.setDefaultLookAndFeelDecorated(true);
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new FrameTitleToolTip().makeUI();
       public void makeUI() {
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(400, 400);
          for (JComponent component : SwingUtils.getDescendantsOfType(JComponent.class,
                frame)) {
             if (component.getClass().getName().contains("MetalTitlePane")) {
                component.setToolTipText("Tooltip for frame title bar");
                break;
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
    }You can get the SwingUtils class [_here_|http://tips4java.wordpress.com/2008/11/13/swing-utils/]
    db

  • Making a JFrame scrollable

    Hi!
    I want to make a JFrame Scrollable.
    How can I do it?
    I am posting my code below.
    JFrame frame = new JFrame("Title");
    JFrame.setDefaultLookAndFeelDecorated(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(true);
    frame.setSize(500,500);
    //adding the panles to the contentpane
    Container contentPane = frame.getContentPane();
    //contentPane.setLayout(new GridLayout(9,1));
    contentPane.setLayout(new BoxLayout(contentPane,BoxLayout.Y_AXIS));
    Thanks

    add a JScrollPane to the contentPane, add a JPanel to the JScrollPane, set the layout on that JPanel and use that JPanel to add other components.

  • Tooltips for JFrame

    Hi,
    I have this GUI application (written in swing), and some times I need to change title of my main frame (JFrame). I do it simple with setTitle() method.
    The problem is that this title is also a tooltip in taskbar. So I need to have JFrame title different from tooltip text in taskbar (when you position mouse pointer on the taskbar).
    Is this possible?
    Any idea?
    Thanx in advance!

    Swing questions should be asked in the swing forum.
    My guess would be that you lose. The tooltip on the taskbar comes from the OS, not java. I'd imagine that the OS just pulls the title from the window and displays that.
    I guess if you really need a hack, you can try making the root frame of your application always hidden, and have the display be a child Dialog of the root frame. That might work, but I haven't tested it and I'm pretty convinced the sheer ick factor outweights most potential benefits.

  • Is there a way to make a JFrame Scrollable

    Hi,
    I having been trying to figure out a way to make a JFrame or JInternalFrame scrollable. Can anyone tell me what is the best approach?
    Thanks!

    Why not use Scrollpane....

  • How can I display the tooltip in a tree node?

    I implement a TreeCellRenderer and has already set the tooltiptext through the following code:
        public Component getTreeCellRendererComponent(JTree tree, Object value,
                               boolean selected, boolean expanded,
                               boolean leaf, int row,
                                  boolean hasFocus) {
            Object userObject = ((DefaultMutableTreeNode)value).getUserObject();
            if(Leaf.class.isInstance(userObject)) {
                    Leaf leaf = (Leaf)userObject;
                    setToolTipText(leaf.getString());
        }Why can't the tree display the tooltip when a move the mouse on the leaf of the tree?
    Thank you!

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    public class Test3 extends JFrame {
    public Test3() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = getContentPane();
    JTree jt = new JTree() {
    public String getToolTipText(MouseEvent evt) {
    if (getRowForLocation(evt.getX(), evt.getY()) == -1)
    return null;
    TreePath curPath = getPathForLocation(evt.getX(),
    evt.getY());
    return curPath.getLastPathComponent().toString();
    content.add(new JScrollPane(jt), BorderLayout.CENTER);
    jt.setToolTipText("");
    setSize(400, 400);
    setVisible(true);
    public static void main(String[] args) { new Test3();
    }It sounds a solution. I use the following code and also can display the tooltip,but there's also a problem:
        mytree.setCellRenderer(new MyTreeCellRenderer());
        ToolTipManager.sharedInstance().registerComponent(mytree);the above code only effective when the function getTreeCellRendererComponent in MyTreeCellRenderer like the following:
        public Component getTreeCellRendererComponent(JTree tree, Object value,
                               boolean selected, boolean expanded,
                               boolean leaf, int row,
                                  boolean hasFocus) {
         String  stringValue = tree.convertValueToText(value, selected,
                                expanded, leaf, row, hasFocus);
         setText(stringValue);
         setToolTipText(stringValue); //Tooltips used by the tree
         /* Set the icon of the node */
                         Object userObject = ((DefaultMutableTreeNode)value).getUserObject();
         if(Device.class.isInstance(userObject)) {
             setIcon(deviceIcon);
         } else {
             setIcon(nullIcon);
             Business b = (Business)userObject;
         setFont(defaultFont);
         /* Update the selected flag for the next paint. */
         this.selected = selected;
         this.hasFocus = hasFocus;
         if(selected) // && hasFocus)
             setForeground(Color.white);
         else
             setForeground(Color.black);
         return this;
        }but when the code is bellow,it displays nothing(Only the leaf node need tooltip):
        public Component getTreeCellRendererComponent(JTree tree, Object value,
                               boolean selected, boolean expanded,
                               boolean leaf, int row,
                                  boolean hasFocus) {
         String  stringValue = tree.convertValueToText(value, selected,
                                expanded, leaf, row, hasFocus);
         setText(stringValue);
         //setToolTipText(stringValue); //Tooltips used by the tree
         /* Set the icon of the node */
                         Object userObject = ((DefaultMutableTreeNode)value).getUserObject();
                         if(Device.class.isInstance(userObject)) {
             setIcon(deviceIcon);
         } else {
             setIcon(nullIcon);
             Business b = (Business)userObject;
             if(b.isShowOrder())
                 setToolTipText(b.getContaId());  // only some node need tooltip, not all  node
         setFont(defaultFont);
         /* Update the selected flag for the next paint. */
         this.selected = selected;
         this.hasFocus = hasFocus;
         if(selected) // && hasFocus)
             setForeground(Color.white);
         else
             setForeground(Color.black);
         return this;
        }Anyone knows why?

  • Is there any way to solve this tooltip issue besides addFocusListener?

    Following up with my last posted thread that now has the record of 23 responds and none relevant to my question, I'm posting another one right now.
    I've managed to reproduce the issue I was talking about and have the code. Basically, my problem was that tooltip was causing popups to go behind the main frame. You can reproduce this by moving your mouse on the table and generate tooltips, after you comment out the focus listener, which is the solution. If table is in focus, tooltips are generated, otherwise, no tooltips.
    What I'm wondering about if anyone knows any other way besides the focus listener to implement this fix and check to see if the table has focus? The reason I'm asking this, although it seems to work fine on this code, is because in my application at work, which has more than 10 panels in it, this table's tooltip problem affects all those other panels as well, not just this story popup on the table. When I open any of the other panels, the table doesn't necessarily lose focus, and when I close them, the table won't necessarily gain back focus, which is what I want to see happen.
    I'd appreciate your relevant suggestions and ideas to my problem. Thanks!
    Here's the code:
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTable;
    import javax.swing.JTextArea;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.DefaultTableModel;
    public class MyTableWithTooltipsTest {
          * @param args
         private JFrame frame;
         private JPanel panel;
         private JTable table;
         public MyTableWithTooltipsTest()
              table = createTable();
            panel = new JPanel(new BorderLayout());
            panel.add(table.getTableHeader(), BorderLayout.NORTH);
            panel.add(table);
            frame = new JFrame("MyTableWithTooltipsTest");
            frame.getContentPane().add(panel);
            frame.setSize(400, 139);
            frame.setVisible(true);
         private JTable createTable()
              Object [][] data = {{"Julie", "Andrews", "10/01/1935"},{"Christopher", "Plummer", "02/18/1954"},
                     {"Hugh", "Jackman", "10/12/1968"}, {"John", "Travolta", "09/18/1964"},
                     {"Olivia", "Newton-John", "09/16/1948"}, {"Stockard", "Channing", "02/13/1944"}};
            String [] columnNames = {"First Name","Last Name","DOB"};
            DefaultTableModel model = new DefaultTableModel(data, columnNames);
            table = new JTable(model);
              table.setDefaultRenderer(Object.class, new ToolTipTableCellRenderer());
            table.addMouseListener(new MouseAdapter()
                 public void mouseClicked(MouseEvent e)
                      int row = table.rowAtPoint(e.getPoint());
                      String story = table.getValueAt(row, 0).toString() + " "+ table.getValueAt(row, 1).toString() + " " + table.getValueAt(row, 2).toString();
                      createStoryPopup(story);
            table.addFocusListener(new FocusListener()
                   public void focusGained(FocusEvent arg0) {
                        table.setDefaultRenderer(Object.class, new ToolTipTableCellRenderer());
                   public void focusLost(FocusEvent arg0) {
                        table.setDefaultRenderer(Object.class, new NoToolTipTableCellRenderer());
              return table;
         private void createStoryPopup(String story)
              JFrame frame = new JFrame("Story");
              JPanel panel = new JPanel();
              JTextArea textArea = new JTextArea(story);
              textArea.setEditable(false);
              panel.add(textArea);
              frame.getContentPane().add(panel);
              frame.setSize(200,50);
              frame.setVisible(true);
         private class ToolTipTableCellRenderer extends DefaultTableCellRenderer {
              public ToolTipTableCellRenderer()
                   super.setBorder(noFocusBorder);
              public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
                   JLabel c = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                   c.setToolTipText(value.toString());
                   return c;
         private class NoToolTipTableCellRenderer extends DefaultTableCellRenderer {
              public NoToolTipTableCellRenderer()
                   super.setBorder(noFocusBorder);
              public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
                   JLabel c = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                   return c;
         public static void main(String[] args) {
              MyTableWithTooltipsTest test = new MyTableWithTooltipsTest();
    }

    Following up with my last posted thread that now has the record of 23 responds and none relevant to my questionAs we told you in your last posting, your question didn't have enough relevant information for us to help solve the problem which is why we asked for a SSCCE.
    I've managed to reproduce the issueSee what happens when you put your mind to creating a SSCCE, instead of wasting time with unnecessary comments complaining about the lack of help?
    Basically, my problem was that tooltip was causing popups to go behind the main frameSorry I still don't see a problem or understand your problem. I've tried the code with and without the FocusListener. In both cases the "popup frame" is always displayed on top of the main frame. This is what I did:
    a) place mouse on the table
    b) wait for popup to display
    c) click on table to show popup
    In both cases the popup was displayed on top of the main frame.
    When the FocusListener code was commented out, I could still get the tooltip. However, when the FocusListener was active, I could not get the tootip to redisplay after the popup was made the active window.
    I'm using JDK6 on XP.
    By the way, normally applications are written with a single JFrame. Additional "popups" would be created by using a JDialog and you would specify the frame as the owner of the dialog. Note this should prevent the dialog from displaying behind the frame.

  • Applet, JFrame: Display icons in toolbar

    Hello,
    I've a class called Designer which extends Applet. In the init method two JFrames are opened: DesignerFrame and DrawPanel. In the DesignerFrame I have a toolbar with icons. When I run the Applet in Eclipse (on my local computer) he shows the icons. When I put the application on my webserver, and I open it with my browser on my local computer, he doesn't show the icons. The icons are in a folder called pwdImages.
    Does anyone know how to solve this problem?
    Thanks a lot!!!
    Koen.

    Hello,
    Thanks for the answers. Here's some code of the DesignerFrame class:
    // Handles color menu items
         class ColorAction extends AbstractAction {
              public ColorAction(String name, Color color) {
                   super(name);
                   this.color = color;
                   String iconFileName = "pwdImages/" + name + ".gif";
                   if (new File(iconFileName).exists())
                        putValue(SMALL_ICON, new ImageIcon(iconFileName));
              public ColorAction(String name, Color color, String tooltip) {
                   this(name, color);
                   if (tooltip != null) // If there is a tooltip
                        putValue(SHORT_DESCRIPTION, tooltip); // ...squirrel it away
              public void actionPerformed(ActionEvent e) {
                   elementColor = color;
                   statusBar.setColorPane(color);
              private Color color;
    addMenuItem(
                   colorMenu,
                   redAction = new ColorAction("Red", Color.RED, "Draw in red"));
    // Element color actions
         private ColorAction redAction, yellowAction, greenAction, blueAction;
    ...

  • Problem with ToolTip Style

    I am trying to set a general style for tooltips and if I try
    and set the border style to solid (or anything besides none) the
    tool tip will only display the text, the background is gone and
    there is no border. Has anyone else run into this problem? I am
    setting the style through the main style sheet.
    ToolTip {
    background-color:#da0303;
    border-style:solid;
    border-thickness:2;
    border-color:#FFFFFF;
    corner-radius:8;
    }

    Try this code
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class UnderlineInSwing extends JFrame {
    public UnderlineInSwing() {
    super("Underline In Swing");
    setSize(400, 300);
    getContentPane().setLayout(new FlowLayout());
    JLabel lab = new JLabel();
              lab.setText("<html><u>Underlined text</u></html>");
    getContentPane().add(lab);
    WindowListener wndCloser = new WindowAdapter(){
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    addWindowListener(wndCloser);
    setVisible(true);
    public static void main(String args[]){
    new UnderlineInSwing();
    sunshine

  • Jtable not scrollable

    My app pops up a new JFrame in which I create and add a JPanel with a scrollable JTable as follows, however no vertical scrollbar appears.
    frame.getContentPane().add(new ResultsPanel(),BorderLayout.CENTER);
    frame.setVisible(true);
    public class ResultsPanel extends JPanel {
        private void jbInit() throws Exception {
           JTable table = new JTable(data, cols);
           table.setPreferredSize(new Dimension(300,200));
           JScrollPane pane = new JScrollPane(table);
           this.add(pane);
    }

    Set the preferred size of the scrollpane, not the table.

  • Tooltip not working in CDC

    Hello every1
    I have tried to attach tooltip with a button and wrote a very simple program for CDC where tooltip is not shown. For confirmation when I compiled that code on J2SE and executed it, it was running fine and showing tooltip. Program is very simple which I am going to copy in this post for reference.
    import javax.swing.*;
    import java.awt.*;
    public class TestTooltip {
    JFrame mainFrame;
    Container frmCont;
    JButton testBut;
    public TestTooltip(){
    mainFrame = new JFrame("Test Tooltip");
    mainFrame.setSize(200,100);
    frmCont = mainFrame.getContentPane();
    frmCont.setLayout(new FlowLayout());
    testBut = new JButton("Tooltip Button");
    testBut.setToolTipText("This is Tooltip");
    frmCont.add(testBut);
    mainFrame.setVisible(true);
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    public static void main(String[] args) {
    new TestTooltip();
    }

    Hello every1
    I have tried to attach tooltip with a button and wrote a very simple program for CDC where tooltip is not shown. For confirmation when I compiled that code on J2SE and executed it, it was running fine and showing tooltip. Program is very simple which I am going to copy in this post for reference.
    import javax.swing.*;
    import java.awt.*;
    public class TestTooltip {
    JFrame mainFrame;
    Container frmCont;
    JButton testBut;
    public TestTooltip(){
    mainFrame = new JFrame("Test Tooltip");
    mainFrame.setSize(200,100);
    frmCont = mainFrame.getContentPane();
    frmCont.setLayout(new FlowLayout());
    testBut = new JButton("Tooltip Button");
    testBut.setToolTipText("This is Tooltip");
    frmCont.add(testBut);
    mainFrame.setVisible(true);
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    public static void main(String[] args) {
    new TestTooltip();
    }

  • How to hide tooltips on user action

    Generally Tooltips will be displayed for the pre-defined time interval. But is there any way to hide the tooltips when the user performs some action.
    Please help me.

    Hi Thanks for your reply.
    But in my case: I have JFrame as main window and JPanel as the workspace. JFrame also had toolbar. User can click a button in the JPanel to replace the existing panel with new panel. The toobar buttons will be changed based on the panel that is currently shown.
    Now,
    1) Focus the button (using keyboard) on the on the panel.
    2) Place the mouse pointer on one of toolbar button to show tooltip.
    3) Press the button (use keyboard) on the panel to get the new panel.
    Do steps 2) and 3) with very less time gap.
    In this case new panel will be displayed with new toolbar icons but the tooltip of previous toolbar button still showing.
    I know the problem is that the tooltip show time is more than the time that took for changing the panel.
    Is there any other way to fix this, instead of decreasing the tool tip dismissdely time.

  • Displaying HTML page from JFrame

    Hi ,
    I have a JFrame GUI with menus and menu items. After Clicking on the Help Menu Item, I want to display a HTML page. Does anyone know of a function to display an HTML page?

    import javax.swing.*;
    import java.awt.*;
    import java.io.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    // This class is used in the Image Tool class when the help menu item is selected
    public class HelpMenu extends JInternalFrame implements HyperlinkListener{
    // A new JEditorPane to display the help html file in.     
    private JEditorPane jep;
         public HelpMenu () {
              super("Help Menu",
                        true, //resizable
                        true,     //closable
                        true,     //maximizable
                        true);     //iconifiable
              // Set the size and location of the frame
              setSize(500,500);
              setLocation(20,20);
              // create the JeditorPane
              jep = new JEditorPane( );
         jep.setEditable(false);
              // Make jep a scrollable pane
              JScrollPane jsp = new JScrollPane(jep);
         getContentPane( ).add(jsp, BorderLayout.CENTER);
              // Add a listener to listen for hyperlinks within the document
         jep.addHyperlinkListener(this);
         try {
         String HelpFile = "file:C:/Documents and Settings/Patrick/Desktop/Help.html";
         jep.setPage(HelpFile);
              // If the file can be loaded display the frame
              setVisible(true);
         catch(Exception e) {
              // The file could not be loaded.
              System.out.println(
                   "Could not open help page! Has it been deleted from: C:/Documents and Settings/Patrick/Desktop/");
              // If the file can not be loaded display an error message
              JFrame f = new JFrame();
         JOptionPane.showMessageDialog(f, "Could not open help page! Has it been deleted from: C:/Documents and Settings/Patrick/Desktop/",
                   "Help Menu", JOptionPane.WARNING_MESSAGE);
              // If the file cannot be loaded do not display a frame
              setVisible(false);
    public void hyperlinkUpdate(HyperlinkEvent he) {
    HyperlinkEvent.EventType type = he.getEventType( );
         if (type == HyperlinkEvent.EventType.ACTIVATED) {
    try {
    // set the page to show the selected section of the file
    jep.setPage(he.getURL( ));
    catch (FileNotFoundException e) {
    catch (Exception e) {
    }     

Maybe you are looking for