Подтвердить что ты не робот

Показать Jframe, но не отображать строку заголовка на панели задач

В моем приложении я показываю Jframe в углу экрана для уведомления. И я хочу показать только Jframe и не отображать строку заголовка на панели задач.

Как я могу это сделать?

4b9b3361

Ответ 1

Если вы хотите, чтобы окно просто появилось и не было ни строки заголовка, ни появилось на панели задач, используйте JWindow.

Если вы хотите, чтобы окно отображалось и имело строку заголовка, но не отображалось на панели задач, используйте JDialog.

Ответ 2

JDK 1.7 предлагает вам метод setType. Используйте следующий метод.

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

Ответ 3

"Все, что вам нужно сделать, - установить свойство типа" JFrame "типа" UTILITY ", и вот оно!"

Это работает, по крайней мере, под Java 1.7, так же, как и вышеописанный "myframe".setType(Type.UTILITY) вместо Type.POPUP. Тип всплывающего типа тестирования (под win 7) не работает, чтобы удалить его с панели задач, Type.UTILITY делает.

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
    }

Ответ 4

Все, что вам нужно сделать, это установить свойство типа "JFrame" "UTILITY" и там у вас есть!

Ответ 5

Вместо этого вы можете попробовать использовать JWindow.

Ответ 6

Просто используйте 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);
   }
}

Ответ 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

Ответ 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

Попробуйте добавить вызов setUndecorated(true);. Он говорит диспетчеру окна не добавлять строки заголовка и окна.

Примечание: это нужно вызывать, пока кадр не отображается.