与我之前的问题相关Java Project - how to freeze Frame , 是否可以使主屏幕的颜色变暗(将所有内容设为灰色或黑白)以突出显示播放器对话框?我该怎么做?
最佳答案
参见 Glass Pane一个完整的例子和解释的例子。
通常您的玻璃板可以使用透明背景:
JComponent glassPane = new JPanel();
glassPane.setBackground( new Color(240, 20, 20, 100) );
frame.setGlassPane( glassPane );
然后当你想显示对话框时,基本代码将是:
glassPane.setVisible( true );
JDialog dialog = new JDialog(...);
// add components to dialog
dialog.setVisible( true );
glassPane.setVisible( false );
关于Java 对话框设置模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4835283/