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.