Every container has a layout manager that is used to position and place components in the container in the desired locations. Three simple and useful layout managers are FlowLayout , GridLayout , and BorderLayout .
You can use a JPanel as a subcontainer to group components to achieve a desired layout.
Use the add method to place components to a JFrame or a JPanel . By default, the frame's layout is BorderLayout , and the JPanel 's layout is FlowLayout .
You can set colors for GUI components by using the java.awt. Color class. Colors are made of red, green, and blue components, each of which is represented by an unsigned byte value that describes its intensity, ranging from 0 (darkest shade) to 255 (lightest shade ). This is known as the RGB model .
The syntax to create a Color object is Color color = new Color(r, g, b) , in which r , g , and b specify a color by its red, green, and blue components. Alternatively, you can use one of the thirteen standard colors ( black , blue , cyan , darkGray , gray , green , lightGray , magenta , orange , pink , red , white , yellow ) defined as constants in java.awt.Color .
Every Swing GUI component is a subclass of javax.swing.JComponent , and JComponent is a subclass of java.awt.Component . The properties font , background , foreground , height , width , and preferredSize in Component are inherited in these subclasses, as are toolTipText and border in JComponent .
You can use borders on any Swing components. You can create an image icon using the ImageIcon class and display it in a label and a button. Icons and borders can be shared.