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.
Related
I am making a collection of button and text field in java. Whenever one of the button is pressed, i want to make the collection invisible/disappear. Is it possible? What collection should i use?
All the buttons and text fields whom you want to make invisible ,keep inside a JPanel. Now when the desired button is pressed you want to make jpanel.setvisible(false).
Write this code inside the ActionListener of that particular button
I am developing some GUI apps in java. I wonder why JFrame.setBackground(Color) and Graphics.setColor(Color) return differ result on screen although I pass the same Color variable?
I create JPanel. It set as JRootPane with setBackground(new Color(0xB7CBEF)). JPanel has a button which draw with overload paintComponent. Inside methode I call Graphics.setColor(0xB7CBEF))..Graphics.fillRect(0,0,button_width, button_heigth). On screen background of button look at little be dark.
Thanks all. Problem was in realize external UI, which some dark background of button in passive condition. Fix this problem with transform button to transparent type.
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.
In my libgdx game, I have 2 screens, menu and list.
When I click on a label in the menu screen, I do a setscreen(list).
The new screen shows up, and the menu screen alongwith its labels disappears.
But when I click on the same positions (from menu screen where the labels were, but of course those labels are not showing as I have changed screens) the click event responds. Why?
note:My list screen currently has not event handlers for any widget.
When switching screens do I need to do anything more than just setscreen(anotherscreen) to deactivate oldscreen?
I changed this :
I moved the input processor to the show() method of that screen using stage variable of that screen
public void show() {
...
Gdx.input.setInputProcessor(stage);
}
before I was setting this only in the constructor of the screen, so even If I was changing the screen, the input processor was still attached to the last created screen's stage
The answer above adiddnt work for me because I dont work with a InputProcessor in the 2nd screen.
My Solution was to set the Inputprocessor to null after setScreen.
Gdx.app.getApplicationListener().setScreen(new Screen());
Gdx.input.setInputProcessor(null);
Just broke my head over this. I changed screens in the show method but had Gdx.input.setInputProcessor(stage) called after that. The method still completed after the show method of the new screen ran and thus reverting back to the previous stage.
So make sure you call Gdx.input.setInputProcessor(stage) before you change screens or return after you change screens.
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.