 |
 |
CocoaJava NSTextField?
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2001
Location: Fluidic Space
Status:
Offline
|
|
I'm new to cocoa programming and I have a small cocoa java problem. By default a NSTextField can be made to send an action when pressing the enter key. What I want is the NSTextField to send an action every time I type a letter or number into the textfield. How can I make it do this?
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2001
Location: London, UK
Status:
Offline
|
|
I can't remember how to do this off the top of my head but there is an example in the Learning Cocoa book that does exactly this. I'm in the process of converting all the examples in the book from Obj-C into Java and I know I've done this one so if no one answers your question before I get home this evening I'll post the converted version.
S.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status:
Offline
|
|
Originally posted by Species 8472:
<STRONG>I'm new to cocoa programming and I have a small cocoa java problem. By default a NSTextField can be made to send an action when pressing the enter key. What I want is the NSTextField to send an action every time I type a letter or number into the textfield. How can I make it do this?</STRONG>
no idea about java, in cocoa all you have to do is to register for the NSControlTextDidChangeNotification for that text field.
should be fairly similar in java.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2001
Location: London, UK
Status:
Offline
|
|
Assuming you have a text field called textField the following code uses the Java version of the NSControlTextDidChangeNotification that seb2 refers to, to print out a line to the console each time you type a character in that field.:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
public class MyController extends NSObject {
NSTextField textField = new NSTextField(); <font color = brown>/* IBOutlet */</font>
public void awakeFromNib() {
NSNotificationCenter nCenter = NSNotificationCenter.defaultCenter();
nCenter.addObserver(this,
new NSSelector(<font color = red>"textDidChange"</font>, new Class[] {
NSNotification.class
}),
NSControl.ControlTextDidChangeNotification,
textField);
}
public void textDidChange(NSNotification notification) {
System.out.print(notification.name() + <font color = red>"\n"</font>);
}
}
</font>[/code]
Hope this helps
S.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2001
Location: Fluidic Space
Status:
Offline
|
|
Originally posted by Synaptic:
<STRONG>Assuming you have a text field called textField the following code uses the Java version of the NSControlTextDidChangeNotification that seb2 refers to, to print out a line to the console each time you type a character in that field.:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre>& amp;lt;font size=1 face=courier>
public class MyController extends NSObject {
NSTextField textField = new NSTextField(); <font color = brown>/* IBOutlet */</font>
public void awakeFromNib() {
NSNotificationCenter nCenter = NSNotificationCenter.defaultCenter();
nCenter.addObserver(this,
new NSSelector(<font color = red>"textDidChange"</font>, new Class[] {
NSNotification.class
}),
NSControl.ControlTextDidChangeNotification,
textField);
}
public void textDidChange(NSNotification notification) {
System.out.print(notification.name() + <font color = red>"\n"</font> );
}
}
</font></pre><HR></BLOCKQUOTE>
Hope this helps
S.</STRONG>
Thanks, this helped me much!
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|