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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2054347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:03:19  来源:igfitidea点击:

show Jframe but not show title bar on task bar

javaswing

提问by Chan Pye

In my application, I show a Jframe at the corner of screen for notification. And I want to show only Jframe and do not display a title bar at task bar.

在我的应用程序中,我在屏幕的角落显示了一个 Jframe 以进行通知。而且我只想显示 Jframe 而不要在任务栏中显示标题栏。

How can I do that?

我怎样才能做到这一点?

回答by lins314159

You could try using a JWindow instead.

您可以尝试改用 JWindow。

回答by Devon_C_Miller

Try adding a call to setUndecorated(true);. It tells the window manager to not add the title bar and window buttons.

尝试添加对 的调用setUndecorated(true);。它告诉窗口管理器不要添加标题栏和窗口按钮。

Note: this must be called while the frame is not displayed.

注意:这必须在不显示框架时调用。

回答by Joe Carnahan

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.

回答by Thabiso Lekena - MVP

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);
   }
}

回答by by cat

/*
 * 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();
    }

}

回答by Sam

All you'd have to do is to set your JFrame "type" property to "UTILITY" and there you have it!

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

回答by Abdo Belk

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

回答by CodeMnke

"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. Testing type popup (under win 7) does not work to remove it from the taskbar, Type.UTILITY does.

这确实有效,至少在 Java 1.7 下,它与上面的“myframe”.setType(Type.UTILITY) 而不是 Type.POPUP 相同。测试类型弹出窗口(在 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
    }

回答by Masudul

JDK 1.7 brings you method setType. Use following method.

JDK 1.7 为您带来了 setType 方法。使用以下方法。

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