Change button's click color in UIManager
Dear all,
I know that it should be done via UIManager
But which method should be used?
It is because it is a button,
is that use getColor(button)??? or anything else.
Thanks
See this page for constants:
http://home.tiscali.nl/~bmc88/java/sbook/061.html
Kaj
Similar Messages
-
How to change the button's clicked color
Dear all,
How to change the button's clicked color
I want it to be white in color as my button's background color is white
ThanksHow to change the button's clicked colorvia the UIManager
-
Hay Guys,
Is there a way to change a button's background color using UIManager when it is presses or selected ?
Thanks a lot,hi,
UIManager.put("Button.foreground", new ColorUIResource(new Color(26,67,92)));.
thanks
daya -
Want to change button background using UIManager for WindowsLookAndFeel
Hi first i used ocean look and feel in my application. i used UIManager to change to color of the button. so all the buttons colors are change. fine
But if i change the look and feel to windows look and feel it shows the windows look only. i sant to change the color to white. how?de to set the look and feel:
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");code to change button property
UIManager.get("Panel.background");
UIManager.put("Button.background", Color.WHITE);
UIManager.put("Button.border", javax.swing.BorderFactory.createLineBorder(Color.black));
UIManager.put("Button.opaque", true);change button properties are not affecting the jbutton. if i create.
But if i remove the setLookAndFeel line properties are applying. why? remedy? is changing the ButtonUI is only option? -
Chaning color when radio button is clicked
I am trying to change the background color when a radio button is clicked. The blue button is the only that I have added an actionListener, but when it is clicked, I get a runtime error. Any suggestions?
[import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Radio
public static void main(String[] args)
JFrame frame = new JFrame("Radio");
Container pane = frame.getContentPane();
JPanel radioPanel = new JPanel();
radioPanel.setLayout(new GridLayout(3,1));
JRadioButton blue = new JRadioButton("Blue", false);
blue.setActionCommand("blue");
JRadioButton red = new JRadioButton("Red", false);
JRadioButton green = new JRadioButton("Green", false);
Radio2 listener = new Radio2(blue, red, green, radioPanel);
blue.addActionListener(listener);
blue.setBackground(Color.BLUE);
blue.setContentAreaFilled(false);
ButtonGroup bg = new ButtonGroup();
bg.add(blue);
bg.add(red);
bg.add(green);
radioPanel.add(blue);
radioPanel.add(red);
radioPanel.add(green);
radioPanel.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "Change Color?"));
frame.add(radioPanel);
frame.setSize(200,200);
frame.setVisible(true);
class Radio2 implements ActionListener
private JRadioButton blue, red, green;
private JPanel radioPanel;
public Radio2(JRadioButton blue, JRadioButton red, JRadioButton green, JPanel radioPanel)
blue = blue;
red = red;
green = green;
radioPanel = radioPanel;
public void actionPerformed(ActionEvent e)
if(e.getActionCommand().equals("blue"))
radioPanel.setBackground(Color.blue);
System.out.println(e.getActionCommand());
]I am trying to change the background color when a
radio button is clicked. The blue button is the only
that I have added an actionListener, but when it is
clicked, I get a runtime error. Any suggestions?
[import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Radio
public static void main(String[] args)
JFrame frame = new JFrame("Radio");
Container pane = frame.getContentPane();
JPanel radioPanel = new JPanel();
radioPanel.setLayout(new GridLayout(3,1));
JRadioButton blue = new JRadioButton("Blue",
", false);
blue.setActionCommand("blue");
JRadioButton red = new JRadioButton("Red", false);
JRadioButton green = new JRadioButton("Green",
", false);
Radio2 listener = new Radio2(blue, red, green,
n, radioPanel);
blue.addActionListener(listener);
blue.setBackground(Color.BLUE);
blue.setContentAreaFilled(false);
ButtonGroup bg = new ButtonGroup();
bg.add(blue);
bg.add(red);
bg.add(green);
radioPanel.add(blue);
radioPanel.add(red);
radioPanel.add(green);
radioPanel.setBorder(BorderFactory.createTitledBorde
r(
BorderFactory.createEtchedBorder(),
edBorder(), "Change Color?"));
frame.add(radioPanel);
frame.setSize(200,200);
frame.setVisible(true);
class Radio2 implements ActionListener
private JRadioButton blue, red, green;
private JPanel radioPanel;
public Radio2(JRadioButton blue, JRadioButton red,
d, JRadioButton green, JPanel radioPanel)
blue = blue;
red = red;
green = green;
radioPanel = radioPanel;
public void actionPerformed(ActionEvent e)
if(e.getActionCommand().equals("blue"))
radioPanel.setBackground(Color.blue);
System.out.println(e.getActionCommand());
]Do me a favor, please. When you post code, put it inside code tags (the button you see above the text area.)
Thanks. -
i have a group of buttons and when each one is clicked its color should change. when another button is clicked the color of previous button should change back to normal..plz help..thanks in advance
Hi Srivatsa,
You can do the same for chnanging your button icons if you have only tow icons to display ....one is default icon and the other one is the icon which you wnat to display when the button is clicked...
Check the below code:
Just replace the image path in the embed variable with your image path and check...
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
private var previousButtonClicked:Button;
[Embed("assets/Rose20Icon.jpg") ]
[Bindable]private var buttonIcon:Class;
[Embed("assets/arrowIcon.JPG") ]
[Bindable]private var buttonIconDefault:Class;
private function buttonClickHandler(event:MouseEvent):void
if(previousButtonClicked)
previousButtonClicked.setStyle("icon",buttonIconDefault);
previousButtonClicked = event.currentTarget as Button;
Button(event.currentTarget).setStyle("icon",buttonIcon);
]]>
</mx:Script>
<mx:HBox>
<mx:Button id="btn1" icon="{buttonIconDefault}" label="Button" color="green" click="buttonClickHandler(event);"/>
<mx:Button id="btn2" icon="{buttonIconDefault}" label="Button" color="green" click="buttonClickHandler(event);"/>
<mx:Button id="btn3" icon="{buttonIconDefault}" label="Button" color="green" click="buttonClickHandler(event);"/>
<mx:Button id="btn4" icon="{buttonIconDefault}" label="Button" color="green" click="buttonClickHandler(event);"/>
<mx:Button id="btn5" icon="{buttonIconDefault}" label="Button" color="green" click="buttonClickHandler(event);"/>
<mx:Button id="btn6" icon="{buttonIconDefault}" label="Button" color="green" click="buttonClickHandler(event);"/>
<mx:Button id="btn7" icon="{buttonIconDefault}" label="Button" color="green" click="buttonClickHandler(event);"/>
</mx:HBox>
</mx:Application>
Thanks,
Bhasker Chari -
hello could somebody please give me the code to make a jbutton change colour when it is clicked on, muuuuuuuuuch appreciated, thanks!!!!!!!!!!!!!!!!!!!!
w e l l - k e w l !
I made a few adjustments here. Mainly for myself:- you know when you JUST CANNOT FIND THAT DARN COLOUR !!! - 'Pandavas' sexy little program is right on the button!
Click on the button and it cycles through colours randomly and tells you the RGB value ...import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ColorChanges extends JFrame implements ActionListener {
int red = 0;
int blue = 0;
int green = 0;
java.util.Random rand = new java.util.Random();
JButton button = new JButton("Colour Me!");
JLabel label1 = new JLabel(" The new colours are: ");
JLabel label2 = new JLabel("");
public ColorChanges() {
super("RGB VALUES:");
setSize(200,108);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button.addActionListener(this);
getContentPane().setLayout(new FlowLayout() );
getContentPane().add(button);
getContentPane().add(label1);
getContentPane().add(label2);
setVisible(true);
public void actionPerformed(ActionEvent eve) {
red = (Math.abs((rand.nextInt())%255));
blue = (Math.abs((rand.nextInt())%255));
green = (Math.abs((rand.nextInt())%255));
cooller();
public void cooller() {
button.setBackground(new Color(red,green,blue));
label2.setText("RED: "+red+" GREEN: "+green+" BLUE: "+blue);
public static void main(String[] args) {
new ColorChanges();
} -
How to change button colors in a loop?
I am working on a task that should imitate an elevator. I have two vertical
rows of round buttons "Up" and "Down" When a circle is selected randomly by
the program, the circle becomes yellow and the elevator moves to that
button.
Here is what I did:
1. created a class Circle where I save buttons' parameters
2. saved Circle objects in an array
3. drew the buttons depending on their parameters
4. generated a random number, matched it with an array index and assigned
the object color to yellow.
Everything is fine except that I can't figure out how to change colors of my
buttons in a loop.
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class Elevator3 extends JPanel
private int n = 40;
private int width = 200;
private int floors = 10;
private int interval = 1000;
private boolean selected = false;
private Circle[] buttons = new Circle[2*(floors-1)];
public Elevator3()
build();
JFrame frame = new JFrame("Elevator3");
setBackground(Color.WHITE);
setFont(new Font("SansSerif", Font.PLAIN, Math.round(n/3)));
frame.getContentPane().add(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width, n*(floors+2) );
frame.setVisible(true);
public void build()
Random r = new Random();
int buttonPick;
int timeUntilNextButton = r.nextInt(interval);
for (int k =0; ; k++)
if (timeUntilNextButton-- ==0)
buttonPick = r.nextInt(2*(floors-1));
//populate my buttons array here - how??
timeUntilNextButton = r.nextInt(interval);
//adding "Down" buttons
for (int i=1, count=0; i < floors; i++, count++)
if (count == buttonPick)
selected = true;
else
selected = false;
buttons[count]= new Circle(n*2, n*i, selected, Math.round(n/2));
//build an array of "Up" circles
for (int i=2, count=floors-1; i < floors+1; i++, count++)
if (count == buttonPick)
selected = true;
else
selected = false;
buttons[count]= new Circle(n, n*i, selected, Math.round(n/2));
public static void main(String[] args)
new Elevator3();
protected void paintComponent(Graphics g)
super.paintComponent(g);
//draw buttons
for (int i=0; i < buttons.length; i++)
g.setColor(buttons.getColor());
g.fillOval(buttons[i].getX(), buttons[i].getY(), buttons[i].getWidth(), buttons[i].getWidth());
class Circle
private int x;
private int y;
private Color c;
private boolean pressed;
private int width;
public Circle(int xCoordinate, int yCoordinate, boolean selected, int diameter)
x = xCoordinate;
y = yCoordinate;
pressed = selected;
width = diameter;
if (pressed)
c = Color.YELLOW;
else
c = Color.LIGHT_GRAY;
public Color getColor()
return c;
public int getX()
return x;
public int getY()
return y;
public int getWidth()
return width;hi,
am sorry, i couldn't make out what exactly the problem, but as ur subject line says...
may be the code give below will help you to change button colors in a loop..
for(int i = 0; i < button.length; i++){
int color1 = (int)(250*Math.random());
int color2 = (int)(250*Math.random());
int color3 = (int)(250*Math.random());
Color c = new Color(color1,color2,color3);
button[i] = new JButton("button name");
button.addActionListener(this);
//to check the r, g, b combination.
//System.out.println(c);
button[i].setBackground(c);
button[i].setForeground(Color.white);
//adding into the panel
panel.add(button[i]);
hope this would help you. -
Question
on firefox clickable buttons are not clickable for me eg the + to open new tab ,the sign in . register and other applications buttons on this page wont click yet the 2 blue change buttons are fineTop of Firefox window non-responsive, toolbars non responsive -- also see [http://kb.mozillazine.org/Problematic_extensions Problematic extensions]
*caused by Yahoo Toolbar -- https://support.mozilla.com/questions/890908
*caused by Babylon Toolbar -- https://support.mozilla.com/questions/890670 -
Change state of the button after clicking
Hi,
I've got following problem - I have navigation tollbar that
consits of buttons. The buttons correspond to different pages of a
content that is shown in Loader. I want the button I've just
clicked to chage its state - so the button has to be highlighted in
order to show which page is currently being viewed.
How can I change the appearance of the button after clicking
it? There'restates like Up, Over, Down, Hit but if I add one more
keyframe and than make button.gotoAndPlay(5) while clicking the
button, nothing happens.
Thank you in advance,
Yuriyuri82_dortmund wrote:
> Hi,
>
> I've got following problem - I have navigation tollbar
that consits of
> buttons. The buttons correspond to different pages of a
content that is shown
> in Loader. I want the button I've just clicked to chage
its state - so the
> button has to be highlighted in order to show which page
is currently being
> viewed.
> How can I change the appearance of the button after
clicking it?
> There'restates like Up, Over, Down, Hit but if I add one
more keyframe and than
> make button.gotoAndPlay(5) while clicking the button,
nothing happens.
Instead of actual button, use Movie Clips with multiple
frames and simply send it
to a frame which simulated DOWN state once pressed.
Best Regards
Urami
<urami>
If you want to mail me - DO NOT LAUGH AT MY ADDRESS
</urami> -
Change Button content when Radio button clicked...
Within my BSP code I have an OnClientClick event against the Radio button tag.
What I need to do is to have some kind of Javascript that changes the context (text) or colour of a button if the Radio button is clicked.
I know very little of how to achieve this and would relish any guidance about how I can get this to work.
I understand that I need to use a reference/handle to the button and change it's values via javascript, but how can I embed this code into my BSP code, what code do I use, and more importantly how can I obtain this reference/handle on the buttion?.
JonHi Jon,
below an Example to do this
(due to security forum restriction replace scrip t with script and o nclick with onclick)
<html>
<head>
<scrip t>
function change_button_text(v_object){
var button = document.getElementById("id_button");
var new_text = v_object.value + ' Clicked!';
if (button.childNodes[0])
button.childNodes[0].nodeValue=new_text;
else if (button.value)
button.value=new_text;
</scrip t>
</head>
<body>
<form>
<input type="radio" name="***" value="male" o nclick="change_button_text(this)"/> Male<br />
<input type="radio" name="***" value="female" o nclick="change_button_text(this)"/> Female
</form>
<button id="id_button">Button Text</button>
</body>
</html>
Edited by: alessandro spadoni on Apr 28, 2011 9:56 AM -
Where is the "firefox button" that is used to change tab location ("click on the Firefox button, go over to the Options... arrow and uncheck Tabs on Top. ") (from article).
The "Tools" menu has an "Options" selection, but I cannot find in any of those menus a selection controlling the location of the tabs. Where is the "Firefox Button" referred to in the article "Why are tabs on Top?"If you turn on the classic menu bar, that replaces the orange Firefox button. To get the Firefox button back, right-click the menu bar to display the toolbars list, and uncheck Menu Bar.
You can always temporarily display the classic menu bar by tapping the Alt key or pressing F10.
The toolbar list pop-up also lets you control Tabs on Top. -
How can I programly change button's blink speed, blink forground/background color?
How can I programly change button's blink speed, blink forground/background color?
Besides changing the LabVIEW.ini, is there another method to achieve?I was about to post a new one on this old thing but came across this when running the exe file from a vi with a blinking and back/foreground color property. In the vi mode everything worked properly as intended with the properties (different color and transparent other than the manual setting under the options->color), including changing the the color under options menu. But the exe file made the BG/FG color to red and yellow while blinking. I came across this topic a long time ago but never used the blinking indicators in the .exe files. NI or someone else has said this is a bug or the default in .exe running environment, please confirm this so I do not have to play around with this.
Also attached is the .ini file from the .exe file and how I add a BG/FG color line to get it working like blue when visible and transparent when not?
Thanks in advance! -
i can get safari to go back to old setting, can anyoner explain how to, i can go to a different web address or see the 3 colors the green ,yellow, or red buttons to click out, how do i reset, and i have went to viewfull screen nothing anyone?
http/:www.apple.com/support/safari
this is not mbp, safari, or lion community -
Problem with changing calenders and reminders colors
Hello,
Somehow the colors of my two of four calendar just changed them self. I've four calendar:
Day Off (mark in yellow), Home (mark as purple), Work (mark as blue) and School (mark in green).
The two calendar of Home and Work swap their color so Home is mark in blue and Work as purple.
I've tried to change it colors many time, tried difference ones two but it keep turning back. Only this two calendar infected.
Same problem in reminder. it keep turning orange from purple.
All attemps in iPhone and in iCloud.com failed.
Appreciate help.even "increment and decrement" buttons of JScrollbar are getting updated with "Button.background" colorWhen you invoke the updateComponentTreeUI() method I believe the code updates the properties of components that use the UIResource interface. The default Colors for components use the ColorUIResource class. See [url http://www.camick.com/java/blog.html?name=uimanager-defaults]UIManager Defaults.
So to prevent a component from being changed you need to replace the ColorUIResource with a Color class for the buttons in question.
You might be able to use Darryl's [url http://www.camick.com/java/blog.html?name=swing-utils]Swing Utils class. You can use the class to get all the JButton components used by the scrollbar. Then for each button you could replace the background by using code like:
button.setBackground( new Color(button.getBackground().getRGB(), true) );
Maybe you are looking for
-
Adding fields to ALV output list in Tcode S_ALR_87012357
Hi, I need your help to insert new fields in output at standard t-code S_ALR_87012357 for GST Report. Report name is RFUMSV00. The add/insert columns are 1)Vendor Description, 2)SGD Gross Amt(100% tax Reporting curr) 3)SGD Tax Base Amt(100% Tax Repo
-
Fiscal year varient creation in BI
Hi, I ahve report where we have already fiscal year varient coming from R/3 it is V3 for specified periods like if i give Fiscal year varient 007.2008 it will add all the last 6 month + this month value and disply on the screen now the client want to
-
Transaction Code to see all automatic account determination GL
Hi All Please let me know the Transaction Code to see all automatic account determination GL like FI -GL integration with other modules/ submodules like AA,MM,SD, FM,CM etc. I tried with FBKP, but it is not giving all. Regards Sekhar
-
I have the 4.2.1 version of itunes i want 4.3
i have the 4.2.1 version of itunes i want the 4.3 but itunes is not getting it?
-
Regenrate SAP_ALL in SU21 transaction
Hello, Needed some info about the 'Regenerate SAP_ALL' button in transaction su21. I created an authorization object in a development client. I then created a new role using PFCG transaction in a customization client to which i assigned the authoriza