您可以执行componentName.setToolTipText(“ context”);有关更多信息,您可以检查关于Swing API的http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html很多有用的信息
我现在看到您想要为JFrame而不是组件执行此操作,这适用于JFrame的标题,也许有帮助
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);
}
}