java如何使JDialog处于非活动状态
我想使基于JDialog的窗口处于非活动状态,以便禁用所有控件(灰色)。setEnabled(false)只会使您无法单击任何控件,甚至无法关闭窗口。但没有什么会变成灰色。请帮忙
编辑:下面是示例代码
import javax.swing.JButton;
import javax.swing.JDialog;
public class Analyzer extends JDialog{
public Analyzer() {
JButton but = new JButton("test");
setLayout(null);
but.setBounds(10,10,100,100);
add(but);
setSize( 200, 200);
setVisible(true);
setEnabled(false);
}
public static void main(String[] args) {
new Analyzer();
}
}
# 1 楼答案
实现这一点的典型方法是使用glassPane,但Java7引入了JLayer,它也应该做到这一点
# 2 楼答案
我知道有两种方法可以做到这一点,一种是递归禁用对话框的组件,另一种是禁用整个对话框(包括拖动对话框的功能):