在一个JFrame中,右上角有一个关闭JFrame的×,我想问问怎么把它屏蔽掉,就像屏蔽最大最小化的按钮一样,使他变为灰色不可用状态。谢谢:)

解决方案 »

  1.   

    用JWindow是连顶部那一行都没有了,我是想问问有没有什么方法可以屏蔽掉关闭按钮×
      

  2.   

    maybe you can disable the message sent to the button ×.Then find some material about message in Java.
      

  3.   

    But how to disable the message?In fact,there is no message-code in a class about the button ×!
      

  4.   

    我把我知道的相关信息告诉你,希望有所帮助。
    JFrame 对象可以通过 setUndecorated(true)方法来把整个标题栏去掉,包括把×去掉。
    JInternalFrame 对象可以把super的参数全部设为false,这样就不会有×,但是仍然有标题栏。
      

  5.   

    import java.awt.*;
    import java.awt.event.*;public class FrameTest {
      static Point origin = new Point();
      public static void main (String args[]) {
        final Frame frame = new Frame();
        frame.setUndecorated(true);
        frame.addMouseListener(new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            origin.x = e.getX();
            origin.y = e.getY();
          }
        });
        frame.addMouseMotionListener(new MouseMotionAdapter() {
          public void mouseDragged(MouseEvent e) {
            Point p = frame.getLocation();
            frame.setLocation(
              p.x + e.getX() - origin.x,
              p.y + e.getY() - origin.y);
          }
        });
        frame.setSize(300, 300);
        Button b1 = new Button("Maximize");
        b1.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            frame.setExtendedState(Frame.MAXIMIZED_BOTH);
          }
        });
        Button b2 = new Button("Iconify");
        b2.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Preserve maximizing
            frame.setExtendedState(Frame.ICONIFIED
               | frame.getExtendedState());
          }
        });
        Button b3 = new Button("Normal");
        b3.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            frame.setExtendedState(Frame.NORMAL);
          }
        });
        Button b4 = new Button("Close");
        b4.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });
        frame.setLayout(new GridLayout(5,1));
        frame.add(b1);
        frame.add(b2);
        frame.add(b3);
        frame.add(b4);
        frame.show();
      }
    }