Java Reference
In-Depth Information
48
49
add(colorJPanel, BorderLayout.CENTER );
50
add(changeColorJButton, BorderLayout.SOUTH );
51
52
setSize( 400 , 130 );
53
setVisible( true );
54
} // end ShowColor2JFrame constructor
55
} // end class ShowColors2JFrame
Fig. 13.7 | Choosing colors with JColorChooser . (Part 2 of 2.)
1
// Fig. 13.8: ShowColors2.java
2
// Choosing colors with JColorChooser.
3
import javax.swing.JFrame;
4
5
public class ShowColors2
6
{
7
// execute application
8
public static void main(String[] args)
9
{
10
ShowColors2JFrame application = new ShowColors2JFrame();
11
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE) ;
12
}
13
} // end class ShowColors2
(a) Initial application window
(b) JColorChooser window
Select a color from
one of the color
swatches
(c) Application window after changing JPanel 's
background color
Fig. 13.8 | Choosing colors with JColorChooser .
Class JColorChooser provides static method showDialog , which creates a JColor-
Chooser object, attaches it to a dialog box and displays the dialog. Lines 36-37 of Fig. 13.7
 
Search WWH ::




Custom Search