show Jframe but not show title bar on task bar

匿名 (未验证) 提交于 2019-12-03 02:03:01

问题:

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.

How can I do that?

回答1:

If you want the window to just appear and have neither a title bar nor appear in the taskbar, use a JWindow.

If you want the window to appear and have a title bar but to not appear in the taskbar, use a JDialog.



回答2:

JDK 1.7 brings you method setType. Use following method.

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


回答3:

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

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.

Undecorated will not have the desired results (as that removes the title bar from the window, not the taskbar)

public class Window extends Container implements Accessible {     /**      * Enumeration of available window types.      *      * 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.      * 

* 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 normal 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 utility 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 popup 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 }



回答4:

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



回答5:

You could try using a JWindow instead.



回答6:

Use this, but it work only on JDK 1.7 or 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 


回答7:

Just use a 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);    } } 


回答8:

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


回答9:

Try adding a call to 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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!