Pages

Set JButton select color

Source code below will show you, how to set JButton select color base on RGB. You can get RGB value for your color using "Color picker" at above.

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


import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.UIManager;

import javax.swing.plaf.ColorUIResource;

public class SetJButtonSelectColor
{
public static void main(String[]args)
{
//Create UIManager object
UIManager manager=new UIManager();


//Key to know : "Button.select"

//Set color base on RGB
//You can get RGB value for your color at "Color picker" at above
//R=255
//G=0
//B=0
manager.put("Button.select",new ColorUIResource(255,0,0));

//Create a button using JButton with text ( CLICK ME AND SEE WHAT COLOR )
JButton button=new JButton("CLICK ME AND SEE WHAT COLOR");

//Create a window using JFrame with title ( JButton select color )
JFrame frame=new JFrame("JButton select color");

//Add created button into JFrame
frame.add(button);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(300,80);

//Make JFrame visible. So we can see it.
frame.setVisible(true);
}
}


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