怎样把JFRAME窗口的"X"关闭按钮变成灰色?
或者把"X"这个按钮去掉?

解决方案 »

  1.   

    这个要修改frame的实现了,我不能做不行,只是这么作了,程序也没有通用型
      

  2.   

    多谢,没有其他的方法了吗?
    如果修改frame的实现,怎么修改呢?
      

  3.   

    我也不会,前几天看到这个问题了,有位大侠给了如下答案,我也还不太懂,你看看吧
    function IfWindowClosed() 
      {   
        var win = null; 
        try 
        { 
          window.opener.name = "ss"; 
          if ( window.opener.name != "ss" ) 
          { 
            win = window.open("quit.asp","","width=100,height=100,left=10000,top=10000"); 
            window.setTimeout("window.close();",0); 
          } 
          window.opener.name = ""; 
        } 
        catch(e) 
        { 
          win = window.open("quit.asp","","width=100,height=100,left=10000,top=10000"); 
          window.setTimeout("window.close();",0); 
        } 
      } 
       
      window.setInterval("IfWindowClosed()",100); 
      window.setTimeout("window.close();",510);
      

  4.   

    我以前写过的code,生成无边框的窗口
    import java.awt.*;
    import java.awt.event.MouseEvent;import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.event.MouseInputAdapter;public class UndecoratedFrame extends JFrame
    {
    private static final int TITLE_HEIGHT = 20; public UndecoratedFrame() throws HeadlessException
    {
    super();
    setUndecorated(true); MouseHandler ml = new MouseHandler();
    addMouseListener(ml);
    addMouseMotionListener(ml);
    } public UndecoratedFrame(String title) throws HeadlessException
    {
    super(title);
    setUndecorated(true); MouseHandler ml = new MouseHandler();
    addMouseListener(ml);
    addMouseMotionListener(ml);
    } public Insets getInsets()
    {
    return new Insets(TITLE_HEIGHT, 1, 1, 1);
    }

    public void paint(Graphics g)
    {
    super.paint(g);
    g.setColor(new Color(0, 0, 128));
    g.drawRect(0, 0, getWidth()-1, getHeight()-1);
    g.fillRect(0, 0, getWidth(), TITLE_HEIGHT); FontMetrics fm = g.getFontMetrics();
    g.setColor(Color.white);
    g.drawString(getTitle(), 2, (TITLE_HEIGHT - fm.getHeight()) / 2 + fm.getAscent());
    }

    private class MouseHandler extends MouseInputAdapter
    {
    private Point point; public void mousePressed(MouseEvent e)
    {
    if (e.getY() <= TITLE_HEIGHT) {
    this.point = e.getPoint();
    }
    }

    public void mouseDragged(MouseEvent e)
    {
    if (point != null) {
    setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); Point p = e.getPoint();
    int dx = p.x - point.x;
    int dy = p.y - point.y;

    int x = getX();
    int y = getY();
    setLocation(x + dx, y + dy);
    }
    }

    public void mouseReleased(MouseEvent e)
    {
    point = null;
    setCursor(Cursor.getDefaultCursor());
    }
    } public static void main(String[] args)
    {
    JFrame f = new UndecoratedFrame("Undecorated Frame");
    f.getContentPane().add(new JLabel("Hello World!", JLabel.CENTER), BorderLayout.CENTER);
    f.setSize(400, 400);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
    }}