Archived:Java ME Gauge progress bar disappears on S60 3rd Edition FP1 (Known Issue)
This known issue was originally created by Cyberal and has been verified by Nokia Developer.
Article Metadata
Tested with
Compatibility
Article
Contents |
Overview
The javax.microedition.lcdui.Gauge progress bar disappears from the form. The label and the space occupied by the progress bar remain on the screen.
Description
When instantiating a new non-interactive Gauge indicating an INDEFINITE maximum value (and possibly a CONTINUOUS_RUNNING value) and changing the Maximum value to make it a DEFINITE gauge, the progress bar disappears. However, if the gauge is instantiated as a DEFINITE value (that is, Max = 100, Val = 50) and changed to INDEFINITE and back, it works.
The same code works on the Sun Java Wireless Toolkit 2.5.2 platform emulator.
How to reproduce
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class GaugeProblem extends MIDlet implements CommandListener {
Form form = new Form("GaugeProblem");
Gauge gauge = new Gauge("Indefinite", false, Gauge.INDEFINITE,
Gauge.CONTINUOUS_RUNNING);
Command exitCommand = new Command("Exit", Command.EXIT, 1);
Command changeCommand = new Command("Change", Command.SCREEN, 2);
public GaugeProblem() {
form.append(gauge);
form.addCommand(exitCommand);
form.addCommand(changeCommand);
form.setCommandListener(this);
}
void init() {
Display.getDisplay(this).setCurrent(form);
}
void changeGauge() {
if (gauge.getMaxValue() == Gauge.INDEFINITE) {
gauge.setLabel("Definite");
gauge.setMaxValue(100);
gauge.setValue(50);
} else {
gauge.setLabel("Indefinite");
gauge.setMaxValue(Gauge.INDEFINITE);
gauge.setValue(Gauge.CONTINUOUS_RUNNING);
}
}
void exitMIDlet() {
try {
destroyApp(true);
} catch (MIDletStateChangeException ex) {
ex.printStackTrace();
}
notifyDestroyed();
}
protected void startApp() throws MIDletStateChangeException {
init();
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
public void commandAction(Command command, Displayable arg1) {
if (command == exitCommand) {
exitMIDlet();
} else if (command == changeCommand) {
changeGauge();
}
}
}
Solution
A workaround to this issue is to instantiate the Gauge with a definite value, and immediately after creation/appending to form, change it to INDEFINITE, and then back to definite as needed.
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class GaugeProblem extends MIDlet implements CommandListener {
Form form = new Form("GaugeProblem");
Gauge gauge = new Gauge("Indefinite", false,
100, //Gauge.INDEFINITE,
50); //Gauge.CONTINUOUS_RUNNING);
Command exitCommand = new Command("Exit", Command.EXIT, 1);
Command changeCommand = new Command("Change", Command.SCREEN, 2);
public GaugeProblem() {
// PATCH TO SOLVE DISAPPEARING GAUGE
gauge.setMaxValue(Gauge.INDEFINITE);
gauge.setValue(Gauge.CONTINUOUS_RUNNING);
// END OF PATCH
form.append(gauge);
form.addCommand(exitCommand);
form.addCommand(changeCommand);
form.setCommandListener(this);
}
void init() {
Display.getDisplay(this).setCurrent(form);
}
void changeGauge() {
if (gauge.getMaxValue() == Gauge.INDEFINITE) {
gauge.setLabel("Definite");
gauge.setMaxValue(100);
gauge.setValue(50);
} else {
gauge.setLabel("Indefinite");
gauge.setMaxValue(Gauge.INDEFINITE);
gauge.setValue(Gauge.CONTINUOUS_RUNNING);
}
}
void exitMIDlet() {
try {
destroyApp(true);
} catch (MIDletStateChangeException ex) {
ex.printStackTrace();
}
notifyDestroyed();
}
protected void startApp() throws MIDletStateChangeException {
init();
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
public void commandAction(Command command, Displayable arg1) {
if (command == exitCommand) {
exitMIDlet();
} else if (command == changeCommand) {
changeGauge();
}
}
}


(no comments yet)