简体   繁体   English

在任务栏上显示 Jframe 但不显示标题栏

[英]show Jframe but not show title bar on task bar

In my application, I show a Jframe at the corner of screen for notification.在我的应用程序中,我在屏幕的角落显示了一个 Jframe 以进行通知。 And I want to show only Jframe and do not display a title bar at task bar.而且我只想显示 Jframe 而不要在任务栏中显示标题栏。

How can I do that?我该怎么做?

If you want the window to just appear and have neither a title bar nor appear in the taskbar, use a JWindow .如果您希望窗口只出现并且既没有标题栏也没有出现在任务栏中,请使用JWindow

If you want the window to appear and have a title bar but to not appear in the taskbar, use a JDialog .如果您希望窗口出现并具有标题栏但不出现在任务栏中,请使用JDialog

JDK 1.7 brings you method setType. JDK 1.7 为您带来了 setType 方法。 Use following method.使用以下方法。

JFrame.setType(javax.swing.JFrame.Type.UTILITY)

"All you'd have to do is to set your JFrame "type" property to "UTILITY" and there you have it!" “您所要做的就是将您的 JFrame“类型”属性设置为“实用程序”,然后就可以了!”

This does work, at least under Java 1.7, its the same as the above "myframe".setType(Type.UTILITY) instead of Type.POPUP.这确实有效,至少在 Java 1.7 下,它与上面的“myframe”.setType(Type.UTILITY) 而不是 Type.POPUP 相同。 Testing type popup (under win 7) does not work to remove it from the taskbar, Type.UTILITY does.测试类型弹出窗口(在 win 7 下)无法将其从任务栏中删除,Type.UTILITY 可以。

Undecorated will not have the desired results (as that removes the title bar from the window, not the taskbar) Undecorated 不会有想要的结果(因为它会从窗口中删除标题栏,而不是任务栏)

public class Window extends Container implements Accessible {
    /**
     * Enumeration of available <i>window types</i>.
     *
     * A window type defines the generic visual appearance and behavior of a
     * top-level window. For example, the type may affect the kind of
     * decorations of a decorated {@code Frame} or {@code Dialog} instance.
     * <p>
     * Some platforms may not fully support a certain window type. Depending on
     * the level of support, some properties of the window type may be
     * disobeyed.
     *
     * @see   #getType
     * @see   #setType
     * @since 1.7
     */
    public static enum Type {
        /**
         * Represents a <i>normal</i> window.
         *
         * This is the default type for objects of the {@code Window} class or
         * its descendants. Use this type for regular top-level windows.
         */
        NORMAL,

        /**
         * Represents a <i>utility</i> window.
         *
         * A utility window is usually a small window such as a toolbar or a
         * palette. The native system may render the window with smaller
         * title-bar if the window is either a {@code Frame} or a {@code
         * Dialog} object, and if it has its decorations enabled.
         */
        UTILITY,

        /**
         * Represents a <i>popup</i> window.
         *
         * A popup window is a temporary window such as a drop-down menu or a
         * tooltip. On some platforms, windows of that type may be forcibly
         * made undecorated even if they are instances of the {@code Frame} or
         * {@code Dialog} class, and have decorations enabled.
         */
        POPUP
    }

您所要做的就是将您的 JFrame“type”属性设置为“UTILITY”,然后就可以了!

您可以尝试改用 JWindow。

Just use a JWindow...只需使用 JWindow ...

import javax.swing.JWindow;
import java.awt.Toolkit;
import java.awt.Dimension;

public class Notification extends JWindow {
   private final int WIDTH = 200;
   private final int HEIGHT = 30;

   public Notification() {
      positionWindow();
      setVisible(true);
   }

   // Place the window in the bottom right corner of the screen
   private void positionWindow() {
      Toolkit aToolkit = Toolkit.getDefaultToolkit();
      Dimension screen = aToolkit.getScreenSize();
      int xPosition = screen.width - (WIDTH + 10); // Right edge of the screen
      int yPosition = screen.height - (HEIGHT + 10); // Bottom edge of the screen
      setBounds(xPosition, yPosition, WIDTH, HEIGHT);
   }
}

Use this, but it work only on JDK 1.7 or openJDK 1.7 :使用它,但它仅适用于 JDK 1.7 或 openJDK 1.7 :

// only on JDK 1.7 or openJDK 1.7

 JFrame f = new JFame(" frame not displayable in the task bar ");
    ...
    ...
    f.setType(Type.POPUP); // No Place on task bar, but stays on top of all others system applications frame
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication4;

import javax.swing.JFrame;

/**
 *
 * @author ravi
 */
public class Main extends JFrame{

    /**
     * @param args the command line arguments
     */
    Main()
    {
       setState(JFrame.ICONIFIED);
        setSize(400, 400);
        setVisible(true);
    }
    public static void main(String[] args) {
        // TODO code application logic here
        Main m=new Main();
    }

}

Try adding a call to setUndecorated(true);尝试添加对setUndecorated(true);的调用setUndecorated(true); . . It tells the window manager to not add the title bar and window buttons.它告诉窗口管理器不要添加标题栏和窗口按钮。

Note: this must be called while the frame is not displayed.注意:这必须在不显示框架时调用。

One answer mentions to use JWindow which works out of the box for Windows and 2 others suggest to use javax.swing.JFrame.Type.UTILITY which is not needed in Windows if you already use JWindow .一个答案提到使用JWindow开箱即用的 Windows 和另外两个建议使用javax.swing.JFrame.Type.UTILITY如果您已经使用JWindow ,则在 Windows 中不需要它。 If you find yourself using JWindow under Linux and you still see it in the taskbar, you can use POPUP instead:如果您发现自己在Linux下使用JWindow并且仍然在任务栏中看到它,则可以改用POPUP

sWindow.setType( Window.Type.POPUP );

Read the documentation though, this might do other things as well (like removing decorations) which you might not need.不过,请阅读文档,这也可能会做其他您可能不需要的事情(例如删除装饰)。

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

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