Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Using text and a progress bar inside of a tooltip.

802561Mar 25 2011 — edited Mar 25 2011
Hi,

I'm trying to get my tool tip to appear as: "Percentage: progressBar," but am not sure how to do so. I've made it so that the progress bar shows up with help from some users on this forum, but am not sure how to use text with it. Here is what I have:
import java.awt.Dimension;
import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JToolTip;
import javax.swing.JProgressBar;

public class ToolTip {

	private JFrame frame;
	
	private JButton button;
	
	private JToolTip testToolTip;

	private JProgressBar progressBar;

	public static void main(String[] var) {
		new ToolTip();
	}

	public ToolTip() {
		progressBar = new JProgressBar(0, 100);
		progressBar.setValue(5);
		progressBar.setStringPainted(true);
        
		testToolTip = new JToolTip() {
			{
				setLayout(new BorderLayout());
				add(progressBar);
			}

			@Override
			public Dimension getPreferredSize() {
				return new Dimension(150, 20);
			}
		};

		button = new JButton("herp") {
			
			@Override
			public JToolTip createToolTip() {
				return testToolTip;
			}
			
		};
		button.setToolTipText("A");
		
		frame = new JFrame("derp");
		frame.setSize(100, 100);
		frame.getContentPane().add(button);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

}
Re-reading this I'm not so sure my point will get across, so pretty much what I want is something that would be implementing a JLabel and JProgressBar inside the same tool tip, having the label and progress bar showing themselves in their respectful way.
This post has been answered by kleopatra-JavaNet on Mar 25 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 22 2011
Added on Mar 25 2011
2 comments
883 views