在我的应用程序中,我在屏幕的一角显示一个Jframe以通知。 我想只显示Jframe并且不在任务栏显示标题栏。
我该怎么做?
答案 0 :(得分:29)
如果您希望窗口只显示并且既没有标题栏也没有出现在任务栏中,请使用JWindow
。
如果您希望窗口显示并有标题栏但未显示在任务栏中,请使用JDialog
。
答案 1 :(得分:12)
JDK 1.7为您带来方法setType。使用以下方法。
JFrame.setType(javax.swing.JFrame.Type.UTILITY)
答案 2 :(得分:5)
“你所要做的就是将你的JFrame”type“属性设置为”UTILITY“并且你拥有它!”
这确实有效,至少在Java 1.7下,它与上面的“myframe”.setType(Type.UTILITY)相同,而不是Type.POPUP。测试类型弹出窗口(在win 7下)无法从任务栏中删除它,Type.UTILITY可以。
未修饰将无法获得所需的结果(因为它会从窗口中删除标题栏,而不是任务栏)
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
}
答案 3 :(得分:3)
您所要做的就是将您的JFrame“type”属性设置为“UTILITY”,并且您拥有它!
答案 4 :(得分:2)
您可以尝试使用JWindow。
答案 5 :(得分:2)
只需使用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);
}
}
答案 6 :(得分:2)
使用它,但它仅适用于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
答案 7 :(得分:1)
/*
* 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();
}
}
答案 8 :(得分:0)
尝试添加对setUndecorated(true);
的通话。它告诉窗口管理器不要添加标题栏和窗口按钮。
注意:必须在未显示框架时调用此方法。
答案 9 :(得分:0)
有一个答案提到要使用JWindow
,它在Windows上是开箱即用的,另外两个则建议使用javax.swing.JFrame.Type.UTILITY
,如果您已经使用JWindow
,则Windows不需要。如果您发现自己在 Linux 下使用JWindow
,但仍在任务栏中看到它,则可以改用POPUP
:
sWindow.setType( Window.Type.POPUP );
不过,请阅读文档,这也可能会做其他您可能可能不需要的事情(例如删除装饰)。