Pages

Set JWindow background color

Source code below will show you how to change JWindow background color. If we directly use setBackground method for JWindow, it seem it's color don't change. So we will use JPanel. In this case, we will set color that we want for JWindow background to JPanel background color. After that we will add the created JPanel into JWindow. So after this, if you want to create a JWindow that contain other components like JTextField or JButton with background color, you must add into a JPanel with background color that you want first. After that, add the JPanel into JWindow.

***********************************************************
COMPLETE SOURCE CODE FOR : SetJWindowBackgroundColor.java
***********************************************************


import java.awt.Color;

import javax.swing.JWindow;

import javax.swing.JPanel;

public class SetJWindowBackgroundColor
{
public static void main(String[]args)
{
//Color is base on RGB
//R=0 , G=219 , B=252
Color color=new Color(0,219,252);

JPanel myPanel=new JPanel();
myPanel.setBackground(color);

JWindow myWindow=new JWindow();
myWindow.add(myPanel);
myWindow.setSize(400,400);
myWindow.setVisible(true);
}
}


***********************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************
Related Posts Plugin for WordPress, Blogger...