-
simple drawing
i have an array of 100 buttons, with icons (that show properly, without a prob), layout using GridLayout
i have a second method that is supposed to change the button's icon. to a differnet icon, (which is in the corrent path and everything is fine, but it doesn't change. when i do
Code:
public void flipTilesToBlank() {
for (int x = 0; x < 100; x++) {
aButton[x].setIcon(new ImageIcon ("blank.jpg"));
aButton[x].paint(aButton[x].getGraphics());
System.out.println(aButton[x].getGraphics());
this.update(aButton[x].getGraphics());
}
}
for the System.out.println(aButton[x].getGraphics()); i get 'null'
what method would i use to redraw after i've set the new image icon, (i'm a bit new to java swing, so not exactly sure, i'm trying the update or i'm trying
aButton[x].paint(aButton[x].getGraphics());
nothing works?? WHY :(
thanx for your help
--770
-
paint is not a method that is meant to be called directly. It is there as a callback for the system. An application should call the repaint method.
:)
-
thank you
but how exactly do i use it??
i'm doing this... (aButton[x].repaint(1, 0, 0, 500, 500);), but doesn't do anything at all
//from the java api 1.4 (sun website)
public void repaint(long tm,
int x,
int y,
int width,
int height)Adds the specified region to the dirty region list if the component is showing. The component will be repainted after all of the currently pending events have been dispatched.
Overrides:
repaint in class Component
Parameters:
tm - this parameter is not used
x - the x value of the dirty region
y - the y value of the dirty region
width - the width of the dirty region
height - the height of the dirty region
--770
-
The Component class has a repaint method that takes no parameters. You can use that one to repaint the whole component.
:)
-
i am doing both of those...
tried both..
repainting the panel it's on and/or the button itself, but it doesn't seem to update...grrr.....
thanx though
--770