3

Related to my previous question Java Project - how to freeze Frame, Is it possible to darken the color of the main screen (make EVERYTHING gray or black and white) to highlight the player dialog box? How can I do that?

Community
  • 1
  • 1
newbie
  • 14,582
  • 31
  • 104
  • 146

1 Answers1

2

See the Glass Pane example for a complete example and explanation.

In general your glass pane can use an transparent background:

JComponent glassPane = new JPanel();
glassPane.setBackground( new Color(240, 20, 20, 100) );
frame.setGlassPane( glassPane );

Then when you want to show the dialog the basic code would be:

glassPane.setVisible( true );
JDialog dialog = new JDialog(...);
// add components to dialog
dialog.setVisible( true );
glassPane.setVisible( false );
camickr
  • 321,443
  • 19
  • 166
  • 288