How to get JButton default background color? - colors

I use this myButton.setBackground(myColor) to change the JButton background color to my color, how to find it's original default background color so I can change it back? I know I can save its default background color before I change and use that, but I wonder if Java stores it somewhere so that maybe I can call something like: myButton.getClass.getDefaultBackground() to get it back ?

btn.setBackground(new JButton().getBackground());
how about this...
it will get the default color of button

myButton.setBackground(null)
changes it back to the default color.

This might help:
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/SystemColor.html
Toolkit.getDesktopProperty(java.lang.String)
Toolkit.getDesktopProperty("control");
// control - The color rendered for the background of control panels and control objects, such as pushbuttons.

It works both with:
button.setBackground(null);
and
button.setBackground(new JButton().getBackground());
(when you create a new JButton, its background color is initialized as a null color)
So, choose the one you consider to be the best for your project

Don't try to get background from Jframe or other elements to apply it on the button; if you already changed it do this:
ElementToStyle.setBackground(null);

make a new button "db"
make a new variable type Color "jbb"
i.e. - Color jbb = db.getBackground();
now the default background color is stored in the Color jbb which you can now use as the color you want to find/use

Color cbt= jButton6.getBackground();
String color_button=cbt.getRed()+","+cbt.getGreen()+","+cbt.getBlue();
if you wont get RGB color button
try this code

Related

How to change color of TEdit when focused

It's probably easy question, bu I can't find an answer.
I want to change background color of TEdit component when I click on it (on Focus), and the background should back to previous color when I click somewhere else.
P.S. I use a Firemonkey and it's multiplatform app, so I need to use a style.
The easiest way (and best) - place TRectangle without Stroke into Tedit, set its Align to Client and change its Fill color in Object Inspector.
Hard way:
Tedit is using bitmap from styles. You can see your current style for Tedit - place StyleBook, Load your style from file, find 'editstyle' object.
You can create a new style for Tedit (copy 'editstyle' in your current style, and name it like editstyle1, select background > Source Link in Object Inspector - select part on global style bitmap with your color, then you can change to new style like Edit1.StyleLookup := 'editstyle1';
Also use a useful forum: http://fire-monkey.ru with Google Translate.

CodenameOne TextView Foreground Color

I'm new to codename one and try to set the foreground (text) color of a TextView. Setting it to red color and writing a text after pressing a button works. The code is executed in button's action listener method:
mValueField.getStyle().setFgColor(0xFF0000); // set red color
mValueField.setText("Fill in!"); // write info text
After setting focus into the field the text should disappear and color should be black again. The code is executed in TextField's focusGained() method:
mValueField.setText(""); // clear info text
mValueField.getStyle().setFgColor(0x000000); // set black color
Problem is that the text disappears but new chars are still red instead of black.
Any solutions for me?
Don't use getStyle() it's designed for use within paint() or similar methods. Since the component has multiple states you need to customize every individual state e.g. getUnselectedStyle(), getSelectedStyle() etc.
Or you can use the getAllStyles() to set them all with a single call.

tvOS button background color issue where it's not set properly

As you can see, I'm trying to set the button's color to a very light blue, but by default everything but the bezels are being darkened. Is the default button behavior causing this? Is there a workaround besides creating your own button? If I do have to create my own button, how can I reuse the default button's animation behavior? Thanks.
You don't have to create a custom button.
Instead, create an image containing the color you want and use that as a background image. Plus make sure to set the button's background color to default (clearColor), otherwise you will lose the rounded corners.

how to change the color of a spinner prompt

I have a spinner with a custom background and I need to change the initially displayed text (the initial prompt) from black to white.
This is what I've got at the moment
There are plenty of answers on SO and elsewhere on how to change the spinner ITEMS color using an adapter but nothing (that I can find) on how to change the initial text (the 'Android' in my example).
How do I change the color of the initial spinner prompt?
Blush ... Oops, I've just found out for myself. The answer is to replicate simple_spinner_item.xml and put it into the layout directory. I had done that but called it simple_spinner.xml, not simple_spinner_item.xml.

How to remove the dark shadow of the screen when a Dialog is shown?

When a Dialog is shown then the background of screen is darkened. I want to remove this darkness so that the screen looks like normal. How to achieve that ?
When you show a Dialog the background becomes a Form, changing its style you can modify the background of a Dialog. I don´t really know if you can make this Form transparent. I use the LWUIT-Theme creator and modifiying the Form´s style, I can change the background for an image o for one colour.
Try it here!
http://lwuit.java.net/
Set the tint color of the parent form, you can also set this in the look and feel class and within the theme constants in the resource editor.
just add below code on your dialog:
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

Resources