It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
who we change the width of the button. i am use 2 buttons. i want display on all width of the screen.
class Main extends UiApplication {
public Main(){
pushScreen(new TestScreen());
}
public static void main(String args[])
{
Main app = new Main();
app.enterEventDispatcher();
}
}
class TestScreen extends MainScreen {
public TestScreen() {
ButtonField bt = new ButtonField("all width"){
public int getPreferredWidth() {
return net.rim.device.api.system.Display.getWidth();
}
};
this.add(bt);
}
}
Related
I have a Vaadin Tabsheet. All tabs are closable. I have defined a custom CloseHandler. When a Tab is closed via the small x button, the the CloseHadler executes; however, if I close the tab programmatically
TabSheet parent = (TabSheet) this.getParent();
parent.removeTab(parent.getTab(this));
The close handler does not execute. Is there a way to force the CloseHandler to execute before the Tab is removed.
Thanks,
Oliver
A solution would be to extend the TabSheet class and override removeTab() to force it to execute the closeHandler. As the TabSheet.closeHandler is private you'll need to override this field and its setter too. Vaadin could make things simpler (changing the closeHandler to protected or providing a getter) but I don't see it as a "dirty" solution.
public class MyTabSheet extends TabSheet {
private static final long serialVersionUID = 1L;
private CloseHandler closeHandler;
#Override
public void removeTab(Tab tab) {
if (closeHandler != null) {
closeHandler.onTabClose(this, tab.getComponent());
}
super.removeTab(tab);
}
#Override
public void setCloseHandler(CloseHandler handler) {
closeHandler = handler;
// needed for TabSheet.TabsheetServerRpcImpl
super.setCloseHandler(handler);
}
}
If you want you could create a feature request at Vaadin (vaadin.com/bug), maybe the closeHandler should be called by default. There's already the #10555 but it's 3 years old...
This question already has answers here:
Enabling/Disabling buttons in JavaFX [duplicate]
(2 answers)
How to disable Button when TextField is empty?
(3 answers)
Closed 7 years ago.
I have a problem with
public class LoginController implements Initializable {
#FXML protected Button loginButton;
#FXML protected TextField email;
#FXML protected PasswordField password;
#Override
public void initialize(URL location, ResourceBundle resources) {
loginButton.disableProperty().bind(Bindings.and(email.textProperty().isEmpty(), password.textProperty().isEmpty()));
}
}
The LoginButton shall be disabled until both fields, email and password, are not empty...
At the moment, the LoginButton is enabled, when I enter one character in either field, leaving the other field alone...
Any ideas, where I got my mistake?
Regards
Use OR:
loginButton.disableProperty().bind(Bindings.or(email.textProperty().isEmpty(), password.textProperty().isEmpty()));
I run this code to make a button then add it to a GridLayout.
private Image makeButton(String text) {
final Image imageButton = new Image(text);
imageButton.setIcon(new ExternalResource("https://cdn2.iconfinder.com/data/icons/ios7-inspired-mac-icon-set/128/_app_store_128.png"));
imageButton.addClickListener(new MouseEvents.ClickListener() {
#Override
public void click(MouseEvents.ClickEvent event) {
Notification.show("Hello World");
}
});
return imageButton;
}
However the click event is never called. Any idea how/why this could happen?
Use setSource() instead of setIcon().
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to add a feature like in the TAMAGO application. When you click on a button, the label will change numbers. If it starts on 100, you tap the egg and "100" changes to "99", tap it again and it will change to "98".
My code is:
`-(IBAction)buttonpress:(id)sender {
if (button.highlighted) {
YES;
label.text = #"999";
if (button.highlighted) {
NO;
label.text = #"998";
}
}`
I tried to repeat this process. But it doesn't work.
This is what you want:
- (IBAction)buttonPress:(UIButton *)sender {
self.myTextLabel.text = [NSString stringWithFormat:#"%d", [self.myTextLabel.text intValue]-1]
}
In this case though the button must have a numeric value when pressed. You could put some further checks in to make sure it is a number if you want. Let me know if you need any further help.
How can i invoke paint multiple time in my app i tried invalidate but but it is not calling paint i think can anybody provide sample code for invoking paint multiple time.
package mypackage;
import com.rss.logger.Log;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
/**
* A class extending the MainScreen class, which provides default standard
* behavior for BlackBerry GUI applications.
*/
public final class MyScreen extends MainScreen
{
BitmapField objBitmapField;
boolean objBoolean;
int postion=0;
public MyScreen()
{
objBitmapField=new BitmapField(Bitmap.getBitmapResource("bb.png"));
// Set the displayed title of the screen
setTitle("MyTitle");
objBoolean=false;
new AnimationThread().start();
}
private class AnimationThread extends Thread{
public void run() {
super.run();
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run()
{
objBoolean=true;
//Add a new LabelField to the screen.
//theScreen.add(new LabelField("Hello there.");
//Call the screen’s invalidate method to
//force the screen to redraw itself.
//Note that invalidate can be called
//at the screen, manager or field level,
//which means you can inform the
//BlackBerry to only redraw the area that
//has changed.
for (int i = 0; i < 20; i++) {
try {
sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.info("in run");
postion=postion+5;
MyScreen.this.invalidate();
}
}
});
}
}
protected void paint(Graphics graphics) {
super.paint(graphics);
Log.info("in paint");
if(objBoolean)
graphics.drawBitmap(20, postion, 50, 50, Bitmap.getBitmapResource("bb.png"), 30, 40);
}
}
Hi piyus find the working code. invalidate() need to call in the paint() method. And one thing is also important that should not create object in paint method.
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.container.MainScreen;
public final class MyScreen extends MainScreen
{
private boolean objBoolean=false;
private int postion=0;
private Bitmap bb=Bitmap.getBitmapResource("bb.png");
public MyScreen()
{
setTitle("MyTitle");
new AnimationThread().start();
}
private class AnimationThread extends Thread
{
public void run()
{
objBoolean=true;
for (int i = 0; i < 20; i++)
{
try
{
sleep(200);
}
catch (InterruptedException e)
{
}
postion=postion+5;
}
}
}
protected void paint(Graphics graphics)
{
super.paint(graphics);
if(objBoolean)
graphics.drawBitmap(20, postion, 50, 50, bb, 30, 40);
invalidate();
}
}
paint() method can be invoked either by using invalidate method or by creating an object of the class that you are using now.
I think there is Typo Error in the sample code you have mentioned here. One cannot have a class inside a class just by defining it. Coming to the issue you are facing
While, calling the invalidate method, as you are using it as MyScreen.this.invalidate which is not the right way to call it, one cannot call the paint method from another class, as in your case it is AnimationThread is not possible. The propreitary feature of Screen class and the paint method is, it gets called once the Object of the screen is created.
And as I understand one can call the invalidate method for a manager or a screen, inside the same class but not by creating an object of the screen in another class and by calling it.
It should be called simply without using any objects simply, invalidate(); , gets the screen repainted or invalidated.
One can also achieve it by creating an object of the same screen, may be if one wanted to display the screen in a different way, they can create an object by using different arguments, and handle it accordingly in the paint method.
Here, whenever the thread is run, you can create an object and handle it according to your choice.
As a sample :
public class theScreen extends MainScreen{
int dummy;
public theScreen(int firstArg){
// Handle the firstArgument here
dummy=0;
}
public theScreen(int secondArg,int dummy){
// Handle the second Argument here
this.dummy = dummy;
}
public void paint(Graphics graphcis)
{
if(dummy == 0)
{
//Handle what you would like to paint here
}
else{
//Handle with a different paint here
}
}}
Hope this resolves your problem
Happy Coding.
Cheers
You may try using Screen.doPaint().
Is your Bitmap big enough to be completely drawn starting from top/left (30, 40)? It may just be that it doesn't look like it's painting because you're outside of the bounds that make sense for it to be drawn.