i use
buttonled1.getBackground().setColorFilter(0xFF00FF00, PorterDuff.Mode.MULTIPLY);
in a function to change the color of a button.
When i first call the function in onCreate() method it works just fine, and the button is created with the color i want.
But when i call in the activity the same function which changes the color of the button again, i have to touch the button to see the color changing.. somehow color changing happens when i want it, but to make it visible i have to touch the button.
Should call buttonled1.invalidate() after setting colorfilter.
Related
Hello I have some questions for adding images for a ImageButton.
I have an icon for example a play button now if I hover over the button it just should get a blue surounding box the inside Image should not change.
Should I draw for every icon the two states or are there other options.
If an button is not clickable it should get Grey. Same how to do this? Add an additional Image to every Icon?
For what is the Checked drawable in the ImageButton?
ImageButtons have a drawable for their background (up, down, over, etc.) and a drawable for the image on top of the button (imageUp, imageDown, imageOver, etc.). The only ones you must provide are up for the background and imageUp for the icon. These are the defaults used when you leave the other states null. But for visual reasons, you need down for the background or it will be hard to tell if the button is being pressed. It's up to you whether you think you need to also change the icon appearance with an imageDown.
All you need is to add the background drawable for disabled. If you want the icon to also turn gray, you need to create a gray version of the icon and assign it to imageDisabled.
The Buttons in Scene2d all support toggle functionality. When you press it, it will toggle to the checked state, so you can use the checked drawable to change its appearance while it is stuck down. If you don't want that to happen, leave the checked drawable null.
I have a JToggleButton, not in a group, and if it's pressed, I want to be able to Un-Select
it if I press another JButton.
I've tried using:
toggleButton.setSelected(false);
toggleButton.doClick();
but neither un-Select the toggle button, it stays "highlighted".
What can I do so that the toggle button goes back to the normal
un-Selected state, like if I pressed it again?
Is it a matter of calling the above while in the UI Thread?
jToggleButton.doClick(): Programmatically perform a "click". This does the same thing as if the user had pressed and released the button.
jToggleButton1.setSelected(false);
jToggleButton1.doClick();
If you execute this code subsequently, it is actually doing nothing. Because, as soon as the first line set the jToggleButton1 as unselected second line set it as selected. If you want just jToggleButton to be unselected use jToggleButton1.setSelected(false) by removing doClick(). But if you want to toggle among selected and deselected using your other JButton click, use jToggleButton1.doClick() only.
Could any one help to implement below thing?
I have custom button which i have overloaded the paintComponent and plainText method to give my own look. the main focus of overridden is to give my own style for buttons.
so here the requirement is originally button background is white and foreground is black and when user press the button the color should revert like background as black and foreground as white.
how can i achieve this?
Instead of subclassing Swing components to modify how they «look and feel», you can provide your own UI implementation and attach it to a normal component instance.
Look at following methods:
'JComponent.setUI(ComponentUI ui)': method to set the UI strategy/decoration
ButtonUI: the UI used for rendering buttons
BasicButtonUI: basic implementation you can extend easily, overwrite paintButtonPressed or the other paint-methods to create your own button look.
I want to change the toggle button background to an image where I click and it gets darker and then once I release it reverts back to the same image. I've managed to successfully do this with a button but I require a toggle button for my app. I tried this with the toggle button and only managed to change the background image of the toggle button. however, the little green check box thing was still there.
I think using the xml drawable for the toggle button is better for your requirement . click here for styling your toggle buttons
I'm developing an Android app.
I have class derived from button to represent a special type of button.
This special type has some properties (integers) and according to these one or more circles have to be drawn on top of the button.
So I overrode the onDraw function, which looks the values up and accordingly draws the circles.
But the class has a function to set new values for its properties. So new values are set but the changes are not reflected in the UI. It seems like the onDraw function is not called.
When later I click the button or show a pop up message above my interface the onDraw function is called and the button is drawn correctly.
So my question: when changing the properties how can I say that the button has to be redrawn?
Thanks a lot!
Call invalidate() on the button to have it (or part of it) redrawn.