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 need to get a callback with every character typed or deleted in EditField in BlackBerry. I need to get the text of EditField as soon as it is written, without losing focus.
There's multiple ways to do this. For example, if you have an EditField instance like this:
private EditField _editField;
then you can subclass EditField and override the keyChar() method:
_editField = new EditField() {
protected boolean keyChar(char key, int status, int time) {
super.keyChar(key, status, time);
// 'key' is the most recent entered char
}
});
or, you can implement a FieldChangeListener and listen for changes:
_editField.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
String text = _editField.getText();
// 'text' is the full text contents of the EditField
}
});
Related
In my UWP app, I detect a keypress by observing the KeyDown event. That gives me a VirtualKey. But how can I tell whether or not the key is a modifier key?
This is the best I have. I'm sure it's incomplete, and it's definitely not future-proof. I'm hoping there is a better answer. In the meantime, others are invited to add keys I missed.
public static VirtualKey[] ModifierKeys =
{
VirtualKey.Shift,
VirtualKey.LeftShift,
VirtualKey.RightShift,
VirtualKey.LeftWindows,
VirtualKey.RightWindows,
VirtualKey.Menu, // aka alt
VirtualKey.Control,
VirtualKey.LeftControl,
VirtualKey.RightControl,
VirtualKey.CapitalLock,
VirtualKey.NumberKeyLock,
VirtualKey.Insert,
};
public static bool IsModifierKey(this VirtualKey key) {
bool r = ModifierKeys.Contains(key);
return r;
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to achieve the functionality of Stage.showAndWait() without using the method itself.
I have an application and I need a way of displaying something within the same stage and block the thread displaying the content until a button is pressed.
The thread displaying the content naturally needs to be tha JavaFX application thread - which of course won't handle the buttons as long as it is blocked.
Stage.showAndWait describes its inner workings as "This method temporarily blocks processing of the current event, and starts a nested event loop to handle other events." I see that the method calls "Toolkit.getToolkit().enterNestedEventLoop(this)", which is pretty implementation specific. Are there any other options? Is functionality like this exposed anywhere in the API?
Edit:
Since my question was misleading, I try to rephrase it more to the point from my current perspective:
Is there a public API for Toolkit.getToolkit().enterNestedEventLoop() and Toolkit.getToolkit().exitNestedEventLoop() ?
For my rephrased question:
Is there a public API for Toolkit.getToolkit().enterNestedEventLoop() and Toolkit.getToolkit().exitNestedEventLoop() ?
Since then the API has been made public in:
javafx.application.Platform.enterNestedEventLoop()
It isn't really clear what you are trying to do, but it sounds like you have some long running process that is building up some kind of data, and then you want the user to control how that built up data is delivered to the screen. In that case, then you need to run a background task to build the data, transfer that data to some element that is available to the FXAT, and then use the action event of a button to move the data onto the screen. Something like this:
public class LongTask extends Application {
StringProperty results = new SimpleStringProperty("");
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
TextArea textArea = new TextArea();
BorderPane root = new BorderPane();
root.setCenter(textArea);
Button button = new Button("More Data");
root.setBottom(button);
button.setOnAction(evt -> textArea.setText(results.get()));
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
Task<Void> sleeper = new Task<Void>() {
#Override
protected Void call() throws Exception {
for (int iteration = 0; iteration < 1000; iteration++) {
try {
Thread.sleep(5000);
int i = iteration;
Platform.runLater(() -> results.set(results.get() + "\nIteration " + i));
} catch (InterruptedException e) {
}
}
return null;
}
};
new Thread(sleeper).start();
}
}
Technically, you don't need to make "results" a property, nor do you need to update it through Platform.runlater(). Using Platform.runlater() guarantees that you won't have concurrency issues with results. Also, if you bind "results" to anything, then you'll need to use Platform.runlater() to modify it.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am creating an application in which I have to check the word typed by user is correct or not using Google dictionary. If the word typed by user is correct, then a toast will be displayed. I am not getting any proper solution on my Google search. So please give me some idea if it is possible.
#Override
public void onGetSuggestions(final SuggestionsInfo[] arg0) {
isSpellCorrect = false;
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < arg0.length; ++i) {
// Returned suggestions are contained in SuggestionsInfo
final int len = arg0[i].getSuggestionsCount();
if(editText1.getText().toString().equalsIgnoreCase(arg0[i].getSuggestionAt(j))
{
isSpellCorrect = true;
break;
}
}
}
You can find the whole project from this link. In above project you can see string is appended. Instead just change the above method onGetSuggestions..
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.
The word table has 2 fields: WORDID and LEMMA. This code shows all records in the word table. But I want to show only certain records like SELECT * WORD WHERE WORDID=10. Can anyone suggest how I can achieve this?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
ConsoleApplication4.DataSet1TableAdapters.wordTableAdapter kata = new DataSet1TableAdapters.wordTableAdapter();
foreach (ConsoleApplication4.DataSet1.wordRow row in kata.GetData())
{
System.Console.WriteLine(row.lemma);
}
System.Console.ReadLine();
}
}
}
Use LINQ?:
ConsoleApplication4.DataSet1TableAdapters.wordTableAdapter kata = new DataSet1TableAdapters.wordTableAdapter();
var query = from p in kata.GetData()
where p.WORDID == 10
select p;
foreach(var item in query)
{
System.Console.WriteLine("{0}, {1}", item.WORDID, item.LEMMA);
}
System.Console.ReadKey();
EDIT:
It's possible that you might have to perform an additional step which I have coded below.
var myTable = kata.GetData();
var query = from p in myTable.AsEnumerable()
where p.WORDID == 10
select p;
You may try this..
foreach (ConsoleApplication4.DataSet1.wordRow row in kata.GetData())
{
if(row.wordid==10)
System.Console.WriteLine(row.lemma);
}
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.
Is it possible to add multiple exception in an try block in c# ?
if possible,please provide with sample code
Thanks,
Santhu
you can provide multiple catch block block for a single try block like this:-
try
{
//your code
}
catch(ExceptionClass e)
{
//code to handle exception
}
catch(ExceptionClass2 e)
{
//code to handle exception
}
catch(ExceptionClass3 e)
{
//code to handle exception
}
but you always have to take care of hierarchy of Exception Classes. like for example, ExceptionClass should not be the Super class of ExceptionClass2 and ExceptionClass3.
Remember to use exceptions from specific to more generics in different catch block
try {}
catch(FileNotFoundException fex) {}
catch(IOExceoption iex) {}
catch(Exception ex) {}
finally {}
Yes
try
{
stuff()
}
catch (Exception1 e1)
{
}
catch (Exception2 e2)
{
}
finally
{
}
You mean like this?
try
{
// Your code
}
catch(an exception)
{
}
catch(a different exception)
{
}
catch(any exception you want)
{
}