无法关闭滚动窗格内文本区域的工具提示 [英] Can't turn off tooltips for text area inside scroll pane

查看:86
本文介绍了无法关闭滚动窗格内文本区域的工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中的所有Swing组件(标签除外)都有一些工具提示,一旦用户知道发生了什么情况,它们就会很烦人,因此我有一个Preferences菜单,可以将其关闭.我可以命名每个组件并将其工具提示文本设置为"(例如,txtPattern.setToolTipText("");](以及其他10个),但是我决定(借助SO始于一段时间)开始编写更加优雅的代码(学习经验):

All Swing components in my app (except labels) have tooltips that can be annoying once the user knows what's going on, so I have a Preferences menu that allows turning them off. I could name every component and set its tooltip text to "" [e.g., txtPattern.setToolTipText("");] (and 10 others), but I decided (with SO aid that started awhile back) to write code that would be more elegant (a learning experience):

  private void tipsOff(Container container){

    Component [] c = container.getComponents();

    for (Component cc : c)
      ((JComponent)cc).setToolTipText("");
  }  

  private void mniPrefTooltipsActionPerformed(java.awt.event.ActionEvent evt) {                                                

    if(! mniPrefTooltips.isSelected()){
       tipsOff(gui.getContentPane());
       tipsOff(gui.pnlLetters);
       tipsOff(gui.mbrMenuBar);
    }
    else{
      gui.dispose();
      gui = new IO();
      gui.setVisible(true);
    }
  }                                               

我有一个问题,即在gui底部的两个大文本区域中未关闭工具提示(在导航器"窗格中突出显示) .正确处理了两个按钮(在导航"窗格中标记为绿色).这些项目应该通过对tipsOff的第一次调用来处理.

I have a problem, which is that the tooltips are NOT turned off for the two large text areas at the bottom of the gui (highlighted in the Navigator pane). The two buttons (marked with green in Nav. pane) ARE processed correctly. These items are supposed to be processed via the first call to tipsOff, which processes gui.getContentPane()).

(我在下面添加了两行以尝试纠正此问题.不是.)

(I added the two lines bellow to try to rectify the problem. Nope.)

tipsOff(gui.scrOutput); 
tipsOff(gui.scrScratch);

(也尝试过.不.)

   tipsOff(gui.txaOutput);
   tipsOff(gui.txaScratchwork);

如何优雅地(即,假设我有很多文本区域,而不仅仅是2个)关闭文本区域工具提示?

How can I elegantly (i.e., assume I have many text areas, not just 2) turn off the text area tooltips?

P.S.除了第一次调用tipsOff以外,我收到所有消息Access of private field of another object.由于手头任务的性质,我不在乎.

P.S. I get the message Access of private field of another object for all but the first call to tipsOff. I don't care, owing to the nature of the task at hand.

推荐答案

使用ToolTipManager.sharedInstance().setEnabled( false )禁用Swing应用程序中的所有工具提示.

Use ToolTipManager.sharedInstance().setEnabled( false ) to disable all tool tips in your Swing application.

与您的方法相比的好处

  • 有效:-)
  • 您无需清除工具提示,因此很容易重新启用它们.例如,如果您想向用户提供UI以激活/停用工具提示,则此方法有效.在您的方法中,您将必须还原以前清除的所有工具提示,而这通常很难实现.

这篇关于无法关闭滚动窗格内文本区域的工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆