简体   繁体   English

Solaris 5.10:如何在任务栏上隐藏JWindow按钮?

[英]Solaris 5.10: How do I hide a JWindow button on the task bar?

I am using a JWindow object in my Java application to simulate a mouseover dropdown menu. 我在Java应用程序中使用JWindow对象模拟鼠标悬停下拉菜单。 When the user mouses over a JLabel, the window appears and remains until the mouse exits either the label or the newly visible window. 当用户将鼠标悬停在JLabel上时,该窗口会显示并保持不变,直到鼠标退出标签或新可见的窗口为止。 My problem is that each time the user performs this action, a new entry in the task bar at the bottom of the screen appears, with no title or icon, and disappears as soon as setVisible(false) is called on the window. 我的问题是,每次用户执行这个动作,在屏幕底部的任务栏出现一个新条目,没有标题或图标,并尽快消失,调用setVisible(假)被称为窗口。

I tried switching to an undecorated JDialog, and this fixed my task bar problem but introduced a new one. 我尝试切换到未装饰的JDialog,这解决了我的任务栏问题,但引入了一个新问题。 When setVisible(true) is called on the JDialog, the focus is taken away from my frame. 在JDialog上调用setVisible(true)时,焦点从我的框架移开。 The color of the title bar changes to indicate this, which looks unprofessional. 标题栏的颜色会更改以表明这一点,这看起来并不专业。

Using an undecorated JFrame, both of the above problems occurred 使用未经修饰的JFrame,会同时发生上述两个问题

I do not wish to use a JInternalFrame as that would require a complete redesign of my interface (switching to the JDesktopPane structure), and I do not require any of the other functionality of the JInternalFrame. 我不希望使用JInternalFrame,因为这将需要完全重新设计我的界面(切换到JDesktopPane结构),并且我不需要JInternalFrame的任何其他功能。

Any ideas? 有任何想法吗?

You can use a JPopupMenu for this. 您可以为此使用JPopupMenu

popupMenu = new JPopupMenu();

Action showPopupAction = new AbstractAction("Show Popup") {
  public void actionPerformed(ActionEvent e) {
    AbstractButton btn = (AbstractButton)e.getSource();
    Point buttonXY = btn.getLocationOnScreen();
    popupMenu.setLocation((int) buttonXY.getX(), ((int) buttonXY.getY()) + btn.getHeight() + 2);
    popupMenu.setVisible(true);
  }
};

JButton btn = new JButton(showPopupAction);

EDIT : An alternative to using a full JPopupMenu is to create a Popup that references your Component , which would require less refactoring; 编辑 :使用完整的JPopupMenu的一种替代方法是创建一个引用您的ComponentPopup ,这将需要较少的重构。 eg 例如

Component myMnu = ...
Popup popup = new Popup(null, myMnu, 100, 100);
popup.show();

Other than that I don't think there's a "quick fix" to your problem: Per the Javadocs, a JWindow is a first class citizen of the desktop, which I imagine is why Solaris is adding a corresponding icon to the task bar. 除此之外,我不认为您的问题有“快速解决方案”:根据Javadocs,JWindow是桌面的一等公民,我想这就是Solaris向任务栏添加相应图标的原因。

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

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