简体   繁体   English

在Java-Swing中构建帮助工具提示

[英]Building Help Tooltips in Java-Swing

I would like to create a simple help system in my Java-Swing application. 我想在我的Java-Swing应用程序中创建一个简单的帮助系统。 I've seen some applications that have a question mark button beside the Window-Buttons. 我见过一些应用程序在Window-Buttons旁边有一个问号按钮。 If you press this button, your cursor changes to a question mark. 如果按此按钮,光标将变为问号。 If you then press something in your application, a help Dialog/Tooltip opens. 如果您然后在应用程序中按某些按钮,则会打开一个帮助对话框/工具提示。 That is exactly what I want to do. 这正是我想要做的。

Is there a default way to do this in Java/Swing applikation or do I have to build it from scratch (with a Classpane for example...). 有没有在Java / Swing applikation中执行此操作的默认方法,或者我是否必须从头开始构建它(例如使用Classpane ...)。

EDIT: 编辑:

I want to open this help screen only if somebody did select the question mark and after that, select a component. 我只想在有人选择问号之后才打开此帮助屏幕,然后选择一个组件。 And I want to keep it open till you press somewhere on the help window. 我想保持打开状态直到你按下帮助窗口的某个地方。

You could make a new Swing component that is composed of two other Swing components. 您可以创建一个由另外两个Swing组件组成的新Swing组件。 One component that you pass in, and another that is made internally that represents the question mark button that opens the tooltip dialog. 您传入的一个组件,以及在内部制作的另一个组件,代表打开工具提示对话框的问号按钮。

public TooltipJComponent extends JPanel
{
    public TooltipJComponent(JComponent someComponent, String tooltipText)
    {
        JButton openTooltip = new JButton("?");
        // add actionListener that opens up a JOptionPane displaying tooltipText
        ...
        this.setLayout(new BorderLayout());
        this.add(someComponent, BorderLayout.CENTER);
        this.add(openTooltip, BorderLayout.EAST);
    }
}

... later in code

blahblahComponent.add(new TooltipJComponent(doConfusingActionButton, 
    "This action adds foos and bars, it's useful because foobar"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM